Skip to content

Instantly share code, notes, and snippets.

@oulrich1
Created January 20, 2018 03:54
Show Gist options
  • Save oulrich1/9d4abca441f707826b6be435bd1e1414 to your computer and use it in GitHub Desktop.
Save oulrich1/9d4abca441f707826b6be435bd1e1414 to your computer and use it in GitHub Desktop.
# 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[@]}"
@oulrich1
Copy link
Author

Mainly a practice in copying from terminal.
:set mouse=
seems to enable OS Selection of text directly..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment