Last active
April 28, 2017 23:43
-
-
Save rock3r/199a7741bd6a0ffb93e7 to your computer and use it in GitHub Desktop.
Move/rename *-{m|h|xh|xxh|xxxh}dpi.png" assets into proper folder structure, ready for copypasta
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# License for any modification to the original (linked below): | |
# ---------------------------------------------------------------------------- | |
# "THE BEER-WARE LICENSE" (Revision 42): | |
# Sebastiano Poggi wrote this file. As long as you retain this notice you | |
# can do whatever you want with this stuff. If we meet some day, and you think | |
# this stuff is worth it, you can buy me a beer in return. | |
# ---------------------------------------------------------------------------- | |
prefix=${1-"drawable"} | |
buckets=( mdpi hdpi xhdpi xxhdpi xxxhdpi ) | |
for density in "${buckets[@]}" | |
do | |
mkdir -p "$prefix-${density}" | |
for f in *-"$density.png" | |
do | |
newName=${f/-$density.png/.png} | |
mv -i "$f" "$prefix-$density/$newName" | |
done | |
done |
As a side note, if your file names don't have dashes but underscores to separate the density bucket from the rest of the file name (e.g. my_image_hdpi.png
instead of my_image-hdpi.png
), just edit line 6 and swap out the -
replacing it with whatever you might need.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist is a
bash
script that takes in all the files in the current directory that match this regex:(.*)-((:?m|h|xh|xxh|xxxh)dpi)\.png$
and renames/moves them to:
drawable-$2/$1.png
E.g.: the file
ic_test_icon-hdpi.png
is moved/renamed todrawable-hdpi/ic_test_icon.png