Skip to content

Instantly share code, notes, and snippets.

@ryanartecona ryanartecona/confirm
Created Dec 14, 2012

Embed
What would you like to do?
Add a sanity confirmation to sensitive commands
# 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
You can’t perform that action at this time.