Last active
January 4, 2023 08:21
-
-
Save kitakkun/54ef923b2fdbe0fc375c8066d68d046c to your computer and use it in GitHub Desktop.
Androidのdrawable整理用シェルスクリプト
This file contains 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
このシェルスクリプトは、Androidプロジェクトにおいてdrawableリソースを整理することを目的に作成されたものです。 |
This file contains 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 | |
# ============================================================= | |
# 特定モジュールが依存しているdrawableリソース名をリストアップするシェルスクリプト | |
# ============================================================= | |
project_root=$1 | |
module_name=$2 | |
code_dir=$project_root/$module_name/src/main/java | |
res_dir=$project_root/$module_name/src/main/res | |
d_in_code=`grep -srEho "R\.drawable\.([a-z]|[A-Z]|[0-9]|_)+" $code_dir` | |
d_in_res=`grep -srEho "@drawable/([a-z]|[A-Z]|[0-9]|_)+" $res_dir` | |
d_in_code=`echo $d_in_code | sed s#R\.drawable\.##g` | |
d_in_res=`echo $d_in_res | sed s#@drawable/##g` | |
drawables=`printf "%s\n%s\n" ${d_in_code[@]} ${d_in_res[@]} | sort -u` | |
for d in $drawables; do | |
echo $d | |
done |
This file contains 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 | |
# ================================================== | |
# 多解像度のdrawableリソースをまとめて移動するシェルスクリプト | |
# ================================================== | |
# 引数の解決 | |
project_root=$1 # Androidプロジェクトのルート | |
drawable_name=$2 # 移動するdrawableのリソース名 | |
dest_module=$3 # 移動先のモジュール名 | |
# 指定したdrawableを各モジュール内で検索 | |
files=`find $project_root/*/src/main/res -name $drawable_name.* -type f -maxdepth 2` | |
# 移動開始 | |
echo "moving $drawable_name..." | |
for file in $files; do | |
file_name=`basename $file` | |
dir_name=`basename \`dirname $file\`` | |
dest=$project_root/$dest_module/src/main/res/$dir_name/$file_name | |
mkdir -p `dirname $dest` | |
mv $file $dest | |
done |
This file contains 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/zsh | |
# ======================================================== | |
# 単一モジュールのみが依存しているdrawableを一括移動するシェルスクリプト | |
# ======================================================== | |
project_root=$1 | |
dest_module=$2 | |
# TODO: ここは処理対象ののAndroidプロジェクトが含むモジュール名のリストになるように適宜書き換えてください! | |
# 例: module_names=(module1, module2, module3) | |
module_names=() | |
typeset -A module_drawables | |
for module_name in ${module_names[@]}; do | |
module_drawables[$module_name]=`drawable_dependency.sh $project_root $module_name` | |
echo $module_drawables[$module_name] > $module_name.txt | |
done | |
unique_drawables=(${module_drawables[$dest_module]}) | |
for module_name in ${module_names[@]}; do | |
if [[ $module_name == $dest_module ]]; then | |
continue | |
fi | |
if [[ -z $module_drawables[$module_name] ]]; then | |
continue | |
fi | |
shared_drawables=(`printf "%s\n%s\n" ${unique_drawables[@]} ${module_drawables[$module_name][@]} | sort | uniq -d`) | |
unique_drawables=(`printf "%s\n%s\n" ${unique_drawables[@]} ${shared_drawables[@]} | sort | uniq -u`) | |
done | |
for d in ${unique_drawables[@]}; do | |
mv_drawable.sh $project_root $d $dest_module | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment