Last active
February 23, 2018 05:49
-
-
Save dulao5/2c1d41a15c0bd71904bab68fe8a878af to your computer and use it in GitHub Desktop.
convert_underscore_case_to_camelCase_variables.sh
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/sh | |
#=============================================================================== | |
# | |
# USAGE: convert_underscore_case_to_camelCase_variables.sh <file名> | |
# | |
# DESCRIPTION: PHPファイルの underscore_case 変数名を camelCase に自動に変換する | |
# | |
#=============================================================================== | |
set -o nounset | |
target_file=$1 | |
if [ ! -f "$target_file" ]; then | |
echo "USAGE: $0 <file名>" | |
exit 1 | |
fi | |
underscore_var_list=$(egrep '\$[_a-z0-9A-Z]+' -o $target_file |sort -u -r | grep _ | egrep -v '\$_[_A-Z]+$') | |
underscore_instance_var_list=$(grep -Po '\->[_a-z0-9A-Z]+(\s*\()?' $target_file | grep -v '(' | sort -u -r | grep _) | |
camelcase_var_name='' | |
for underscore_var_name in $underscore_var_list $underscore_instance_var_list | |
do | |
camelcase_var_name=$(echo $underscore_var_name | sed -e 's/\([a-z0-9]\)_\([a-z]\)/\1\U\2/g') | |
if [ 1 == $(echo -en "$camelcase_var_name\n$underscore_var_name\n" | sort -u | wc -l) ]; then | |
echo -e "skip convert \t $underscore_var_name \t to \t $camelcase_var_name" | |
continue | |
fi | |
message="now convert \t $underscore_var_name \t to \t $camelcase_var_name" | |
sed -e 's/'$underscore_var_name'/'$camelcase_var_name'/g' -i $target_file | |
if [ $(which git) ]; then | |
commit_message="auto-convert : '$underscore_var_name' → '$camelcase_var_name'" | |
git add $target_file > /dev/null 2>&1 \ | |
&& git commit -m "$commit_message" $target_file > /dev/null 2>&1 \ | |
&& message="$message\t"$(git rev-parse --short HEAD) | |
fi | |
echo -e "$message" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
git rebase 后 hash 被重新整理