Created
January 20, 2018 03:54
-
-
Save oulrich1/9d4abca441f707826b6be435bd1e1414 to your computer and use it in GitHub Desktop.
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
# length of maximum digit to enumerate song list | |
function get_digit_length() { | |
list=("$@") | |
length="${#list[@]}" | |
((length++)) | |
length="${#length}" | |
echo "$length" | |
} | |
# pad with 0's in front. the number of zeros | |
# is represented by the second parameter | |
function get_formatted_index() { | |
index="$1" | |
repl="%0$2"d | |
printf -v num $repl $index; | |
echo $num; | |
} | |
# enumerate the song list and copy song with enumeration as name | |
function rename_files() { | |
ext="$1" | |
shift | |
fileList=("$@") | |
length="$(get_digit_length ${fileList[@]})" | |
# store the new files | |
newPath="./new" | |
mkdir -p $newPath | |
# copy the files to the new directory | |
index=1 | |
for song in "${fileList[@]}"; do | |
newName="$(get_formatted_index $index $length)" | |
newName="$newName.$ext" | |
echo "Copying $song to $newPath/$newName" | |
cp $song $newPath/$newName | |
((index++)); | |
done | |
} | |
newSongList=( | |
) | |
## TODO: get each line from a pipe via xargs. | |
## | |
rename_files "mp3" "${newSongList[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mainly a practice in copying from terminal.
:set mouse=
seems to enable OS Selection of text directly..