Last active
December 30, 2015 10:39
-
-
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.
This file contains hidden or 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
# 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 | |
} |
This file contains hidden or 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
# If you don't want to be prompted, use this one | |
del() { | |
mv -v $* $HOME/.Trash/; | |
} |
This file contains hidden or 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
# 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