From 237ce731d2c1d159cf3d2e98d1ea486e9853fa7b Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Thu, 6 Nov 2014 12:35:45 -0600 Subject: [PATCH] Add prod command trap to save myself from utter destruction. --- .bash_profile | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.bash_profile b/.bash_profile index a2a6b2c..d4ecb8a 100644 --- a/.bash_profile +++ b/.bash_profile @@ -66,3 +66,20 @@ export ANSIBLE_NOCOWS=1 # Ansible aliases. alias an='ansible' alias ap='ansible-playbook' + +# Ask for confirmation when 'prod' is in a command string. +prod_command_trap () { + if [[ $BASH_COMMAND == *prod* ]] + then + read -p "Are you sure you want to run this command on prod [Y/n]? " -n 1 -r + if [[ $REPLY =~ ^[Yy]$ ]] + then + echo -e "\nRunning command \"$BASH_COMMAND\" \n" + else + echo -e "\nCommand was not run.\n" + return 1 + fi + fi +} +shopt -s extdebug +trap prod_command_trap DEBUG