mirror of
https://codeberg.org/hyperreal/bin
synced 2024-11-25 10:23:42 +01:00
Add new lispify script
This commit is contained in:
parent
ec933d2df1
commit
e79bedc940
42
lispify
42
lispify
@ -1,12 +1,34 @@
|
|||||||
#!/usr/bin/env zsh
|
#!/bin/bash
|
||||||
|
|
||||||
# Lispify - convert file names to-lisp-case
|
# This script was written entirely by ChatGPT 4.
|
||||||
filename=$(basename -- "$1")
|
|
||||||
extension="${filename##*.}"
|
# Check for an argument
|
||||||
filename="${filename%.*}"
|
if [ $# -eq 0 ]; then
|
||||||
new_filename=$(echo ${filename// /-} | tr '_' '-' | tr -cd '[:alnum:]._-')
|
echo "Usage: $0 filename"
|
||||||
new_basename=$(echo "$new_filename.$extension")
|
exit 1
|
||||||
mv -i "$1" "$new_basename"
|
fi
|
||||||
if ! [ "$new_basename" = "${new_basename:l}" ]; then
|
|
||||||
mv -i "$new_basename" "${new_basename:l}"
|
# A function to convert a string to Lisp case
|
||||||
|
to_lisp_case() {
|
||||||
|
echo "$1" | awk '{ gsub(/_/,"-"); print tolower($0) }' | sed 's/[A-Z]/-\L&/g' | sed 's/^-//'
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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 Lisp case."
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user