Skip to content

Instantly share code, notes, and snippets.

@perguth
Last active May 26, 2022 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perguth/7eedf813f46c1116870b7fc12aa420e6 to your computer and use it in GitHub Desktop.
Save perguth/7eedf813f46c1116870b7fc12aa420e6 to your computer and use it in GitHub Desktop.
β²οΈπŸ“ Back ups every file that gets touched by `nano`.
#!/bin/sh
# Back ups every file that gets touched by `nano`.
# Install by:
# 1. `sudo mv /bin/nano /bin/nano-real`
# 2. Put this file in `/usr/local/bin` and make it executable.
# 3. Set your user:
backupFolder=$HOME/.system-changes
currentFolder=$(pwd)
# If directory: exit.
if [ -d $1 ]; then
echo πŸ“ Look, it\'s a folder.
exit
fi
# First time use. Auto setup.
if ! stat $backupFolder > /dev/null 2>&1; then
echo πŸ‘‹ First time use. Hello there!
mkdir -p $backupFolder
cd $backupFolder
git init
cd $currentFolder
fi
# If file does not exist: exit.
if ! stat $1 > /dev/null 2>&1; then
nano-real $1
exit
fi
path=$backupFolder/$currentFolder
mkdir -p $path
cp -rf $1 $path
cd $path
git add . > /dev/null
git commit -m "⏲️ $path" > /dev/null
cd $currentFolder
nano-real $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment