Скачивание/обновление файла git_capitalize.sh:
$ curl -o git_capitalize.sh https://gist.githubusercontent.com/smgladkovskiy/7184020/raw/git_capitalize.sh
#!/bin/bash | |
# | |
# Shell script to capitalise files and directories | |
# in case insensitive OS (i.e. Windows) | |
# | |
# Point to a file or directory in witch you want to | |
# capitalize it name: git_uppercase.sh /path/to/directory/or/file | |
# | |
# It works recursivelty by dafault | |
if [[ -d $1 ]]; then | |
FILES="$1/*" | |
elif [[ -f $1 ]]; then | |
FILES="$1" | |
else | |
echo "What '$1' this is for?" | |
exit 1 | |
fi | |
# Main remaining function | |
function renaming() | |
{ | |
if [[ -d $1 ]]; then | |
renaming_dir "$1/*" | |
renaming_file $1 | |
elif [[ -f $1 ]]; then | |
renaming_file $1 | |
else | |
echo "$1 is not valid" | |
exit 1 | |
fi | |
return 1 | |
} | |
# Directory remaining function | |
function renaming_dir() { | |
echo -e "\nGoing into $1 to rename:\n" | |
for more_file in $1 | |
do | |
renaming $more_file | |
done | |
echo -e "\n" | |
} | |
# File remaining function | |
function renaming_file() { | |
echo "renaming file $1" | |
local file_name=`basename $1` | |
local file_path=`dirname $1` | |
local file_name_with_suffix=`echo "$file_name"_` | |
local file_name_uc=`echo "$file_name" | tr '[A-Z]' '[a-z]' | sed 's/\(^\|\.\/\)\([a-z]\)/\1\u\2/g'` | |
git mv $file_path/$file_name $file_path/$file_name_with_suffix | |
git mv $file_path/$file_name_with_suffix $file_path/$file_name_uc | |
return 1 | |
} | |
# Capitalize! | |
for file in $FILES | |
do | |
renaming $file | |
done |