Add "undelete" feature to your home directory

  1. Set up your system in such a way that your home directory is covered by BTRFS.
  2. Setup Snapper [1].
  3. Setup your system in such a way that snapshots are available under /home/.snapshots
  4. Add the “undelete” script in your \$HOME/bin, make sure it is executable, and make sure \$HOME/bin is in your \$PATH.

The "undelete" script

#!/bin/bash
echo Undeleting "$1"...
cp -ir /home/.snapshots/$(ls -1 /home/.snapshots/ | tail -1)/snapshot/$(echo $(pwd)| cut -d '/' -f 3-)/$1 ./