aboutsummaryrefslogblamecommitdiffstats
path: root/zetrename.sh
blob: e1a178d0417202bbe3c494e12692a425a66c9389 (plain) (tree)
1
2
3
4
5
               


                                                                                                                  
                                        











                                                              
                                                                                         

















                                                                                                                    
#!/usr/bin/bash

# Renaming files of the format YYYYMMDDHHMMSS-title text etc.md is a massive pain, so this script does it for you.

NOTES=/home/$USER/Documents/Notes/modzet

function usage {
    echo
    echo "Usage: zetrename [PATH] [NAME]"
    echo " Renames a zet file, retaining original time stamp."
}


if [[ $# -eq 0 ]]; then
    usage; exit 1
fi

# path must be of form /home/$USER/Documents/Notes/modzet/20220419133511-Title of file.md

#re='^/tmp\/Notes\/modzet\/(.{14})-(.+)\.md'
re='^/home\/lemon\/Notes\/modzet\/(.{14})-(.+)\.md'
if [[ "$1" =~ $re ]]; then
	notedate=${BASH_REMATCH[1]}
	oldname=${BASH_REMATCH[2]}
else
	echo "Please ensure you pass an appropriate absolute path to the file to be renamed or ensure it is quoted."
	exit 1
fi

NEW_PATH="$NOTES/$notedate-$2.md"

echo "$NEW_PATH"


# rename
mv "$1" "$NEW_PATH"