Created
December 14, 2012 06:44
-
-
Save ryanartecona/4283221 to your computer and use it in GitHub Desktop.
Add a sanity confirmation to sensitive commands
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
# with help from | |
# http://stackoverflow.com/questions/3231804/in-bash-how-to-add-are-you-sure-y-n-to-any-command-or-alias | |
# and | |
# http://stackoverflow.com/questions/1537673/how-do-i-forward-parameters-to-other-command-in-bash-script | |
function confirm( ) { | |
#confirm with the user | |
read -r -p "$* [y/n]: " response | |
case "$response" in | |
[yY][eE][sS]|[yY]) | |
#if yes, then execute the passed parameters | |
"$@" | |
;; | |
*) | |
#Otherwise exit... | |
echo "cancelled." | |
;; | |
esac | |
} | |
# make sure it works properly | |
alias ls='confirm ls' | |
# protect my terminal from myself | |
alias kill='confirm kill' | |
alias pkill='confirm pkill' | |
#etcetera |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment