Created
March 15, 2024 14:58
-
-
Save knollet/334efa495709e507038135543d0da3e8 to your computer and use it in GitHub Desktop.
Trash on the shell. Small bashrc implementation
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
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