-
-
Save perguth/7eedf813f46c1116870b7fc12aa420e6 to your computer and use it in GitHub Desktop.
β²οΈπ Back ups every file that gets touched by `nano`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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