Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@itsthatguy
Last active December 30, 2015 10:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save itsthatguy/7817428 to your computer and use it in GitHub Desktop.
Save itsthatguy/7817428 to your computer and use it in GitHub Desktop.
The `rm` command is destructive. Here's a command to move files to the trash, with a prompt, instead of deleting permanently.
# Add this to your .bash_profile, .bashrc, .zshrc or wherever you keep your bash functions and aliases.
del() {
RED="\e[31m"
YELLOW="\e[33m"
WHITE="\e[97m"
if [[ $# -eq 0 ]] ; then
echo -e "Sorry dude, I can't do anything with that. Nothing specified."
else
echo -ne "${YELLOW}You're about to move the following items to the trash:${RED}\n > $*\n${YELLOW}Are you sure? [y/n] "
read answer
finish="-1"
while [ "$finish" = '-1' ]
do
finish="1"
if [ "$answer" = '' ];
then
answer=""
else
case $answer in
y | Y | yes | YES )
echo "$reset_color"
mv -v $* $HOME/.Trash/;
answer="y";
;;
n | N | no | NO ) answer="n";;
*) finish="-1";
echo -n '\nInvalid response -- please reenter:';
read answer;;
esac
fi
done
fi
}
# If you don't want to be prompted, use this one
del() {
mv -v $* $HOME/.Trash/;
}
# If all you want is to be prompted, and don't care about moving
# files to the trash, you could use the following:
alias rm="rm -i"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment