bin/lispify

33 lines
774 B
Plaintext
Raw Normal View History

2023-11-08 16:55:42 +01:00
#!/bin/bash
# Check for an argument
if [ $# -eq 0 ]; then
echo "Usage: $0 filename"
exit 1
fi
# A function to convert a string to Lisp case, including converting spaces to a single dash
2023-11-08 16:55:42 +01:00
to_lisp_case() {
echo "$1" | awk '{ gsub(/[ _]+/, "-"); print tolower($0) }' | sed 's/[A-Z]/-\L&/g' | sed 's/^-//'
2023-11-08 16:55:42 +01:00
}
# The filename is the first argument
file="$1"
# Check if the file exists
if [ ! -f "$file" ]; then
echo "Error: File does not exist."
exit 1
fi
# Convert the filename to Lisp case
new_name=$(to_lisp_case "$file")
# Rename the file if the new name is different from the original
if [ "$file" != "$new_name" ]; then
mv -- "$file" "$new_name"
echo "File renamed to $new_name"
else
echo "File name is already in the desired format."
2023-08-11 18:48:18 +02:00
fi