Skip to content

Instantly share code, notes, and snippets.

@rock3r

rock3r/prepareassets.sh

Last active Apr 28, 2017
Embed
What would you like to do?
Move/rename *-{m|h|xh|xxh|xxxh}dpi.png" assets into proper folder structure, ready for copypasta
#!/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
@rock3r

This comment has been minimized.

Copy link
Owner Author

@rock3r rock3r commented Jan 8, 2015

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 to drawable-hdpi/ic_test_icon.png

@rock3r

This comment has been minimized.

Copy link
Owner Author

@rock3r rock3r commented Jan 8, 2015

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
You can’t perform that action at this time.