Skip to content

Instantly share code, notes, and snippets.

@perguth

perguth/nano

Last active Sep 13, 2019
Embed
What would you like to do?
⏲️📝 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