An arbitrary collection of fleeting thoughts & projects
Published: February 21, 2024 • Category: Development • Tags: notepad++, sketches, tag1
#!/bin/bash
echo
echo Copying "$1" to "$1"-`date +"%Y%m%d-%H%M%S"`.txt.html
cp "./$1" ./"$1"-`date +"%Y%m%d-%H%M%S"`.txt.html
echo
All it did was simply copy the filename I supplied on the command line, to a hidden file name, and dropped in a date and time stamp, using and reformatting the date command.
This worked, **but** I needed to remember to run Copy before I edited the file with Vi.
Better Edit
Then, later on, I created an Alias to easily run Notepad++”:
alias npp=/mnt/c/'Google Drive'/Utilities/Notepad++/Notepad++.exe
Now all I needed to do was first fune my Copy script, then use the npp alias to edit the file in Notepad++.
Put it all Together
Finally, I put it alll together into a script called Edit which hits all my requirements; backup files before I edit them, Transparent to me, and a better editor.
The biggest change I made was the creation of .backups folders to house the backups created in each folder, keeping them out of the way (transparent) while still keeping things in order.
Her’s the final version of the file.
# !/bin/bash
NOW=$(date +"%Y.%m.%d,%H.%M.%S")
FILE="$1"
if [ -z "$FILE" ]
then
echo "ERROR: Need a file on the command line"
else
mkdir ./.backup > /dev/null 2>&1
cp "./$1" .backup/`date +"%Y%m%d-%H%M%S"`.$1 > /dev/null 2>&1
echo Editing $1 in Notepad++
/mnt/c/'Google Drive'/Utilities/Notepad++/Notepad++.exe $1
fi
Please let me know if you have suggestions on how to do this better, smarter or simpler.