trash-cli
trash-cli copied to clipboard
More safety Tips / Suggestions
This is not really a bug but a TIP. (zsh related). I do not know where else can I put it.
Just sharing a few line code (zsh only) which others may be in search for. (because I searched too and finally made one on my own)
Purpose:
- trash / trash-put should ask before trashing, just like rm -i
- trash-put should not trash directory but just a regular file
- trash-empty and trash-rm should ask first. Infact ask twice, because its going to be erased forever! (Intention is to be 100% sure!)
- If user uses rm instead of trash-put, ask first before running rm
Here is the code: (put in your .zshrc)
if (( $+commands[trash-put] )); then
rm() {
if read -q "?$0: are you sure you do NOT want to use trash-put? [N/y] "; then
echo ""
nocorrect command rm -i "$@"
fi
}
trash-put() {
local file;
for file in "$@"; do
if [[ ! -f $file ]]; then
echo "$0: cannot remove '$file': not a regular file"
continue
fi
if read -q "?$0: trash regular file '$file'? [N/y] "; then
echo ""
nocorrect command trash-put -v -- $file
fi
done
}
alias trash=trash-put
fi
if (( $+commands[trash-rm] )); then
trash-rm() {
if read -q "?$0: are you sure you want to use trash-rm? [N/y] "; then
echo ""
if read -q "?$0: are you REALLY sure you want to use trash-rm? [N/y] "; then
echo ""
nocorrect command trash-rm "$@"
fi
fi
}
fi
if (( $+commands[trash-empty] )); then
trash-empty() {
if read -q "?$0: are you sure you want to empty trash? [N/y] "; then
echo ""
if read -q "?$0: are you REALLY sure you want to empty trash? [N/y] "; then
echo ""
nocorrect command trash-empty "$@"
fi
fi
}
fi
Hope it helps!
Related to https://github.com/andreafrancia/trash-cli/issues/10
From the 0.21.5.25 release trash-put honors the -i option.
Example:
$ touch foo
$ trash-put -i foo
trash-put: trash regular empty file 'foo'? y
$
You can add alias trash-put='trash-put -i' to your .bashrc