bin/snakify
2023-08-11 11:48:18 -05:00

13 lines
400 B
Bash
Executable File

#!/usr/bin/env zsh
# Snakify - convert file names to_snake_case
filename=$(basename -- "$1")
extension="${filename##*.}"
filename="${filename%.*}"
new_filename=$(echo ${filename// /_} | tr '-' '_' | tr -cd '[:alnum:]._-')
new_basename=$(echo "$new_filename.$extension")
mv -i "$1" "$new_basename"
if ! [ "$new_basename" = "${new_basename:l}" ]; then
mv -i "$new_basename" "${new_basename:l}"
fi