Skip to content

Instantly share code, notes, and snippets.

@knollet
Created March 15, 2024 14:58
Show Gist options
  • Save knollet/334efa495709e507038135543d0da3e8 to your computer and use it in GitHub Desktop.
Save knollet/334efa495709e507038135543d0da3e8 to your computer and use it in GitHub Desktop.
Trash on the shell. Small bashrc implementation
function trash {
TRASHDIR="$HOME/TRASH"
DATE="$(date '+%Y-%m-%d_%H:%M:%S.%N')"
if [ -z "$1" ]; then
echo "usage: $0 <filenames...>" > /dev/stderr
exit 1
fi
for FILE in "$@"; do
DEST="$TRASHDIR/$DATE/$(dirname "$(realpath --relative-to "$HOME" -s "$FILE")")"
mkdir -p "$DEST"
mv "$FILE" "$DEST"
done
}
function trash-ls {
TRASHDIR="$HOME/TRASH"
ls "$TRASHDIR"/*
}
function trash-empty {
TRASHDIR="$HOME/TRASH"
echo "really clear trash?"
select yn in "Yes" "No"; do
case $yn in
Yes )
chmod -R +w "$TRASHDIR"
rm -rf --one-file-system "$TRASHDIR"/*;
break;;
No ) exit;;
esac
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment