Skip to content

Instantly share code, notes, and snippets.

@addiedx44
Last active July 27, 2016 13:26
Show Gist options
  • Save addiedx44/5638037 to your computer and use it in GitHub Desktop.
Save addiedx44/5638037 to your computer and use it in GitHub Desktop.
Runs the last command with sudo if you curse at your terminal. Add this to your .bashrc.
# Runs the last command with sudo if you curse at your terminal.
#
# $ whoami
# adam
# $ how about now, motherfucker?
# root
#
debug_trap () {
re="(fuck|shit)"
if [[ $BASH_COMMAND =~ $re ]]; then
sudo bash <<EOF
$(history -p !-1)
EOF
return 1
fi
}
shopt -s extdebug
trap debug_trap DEBUG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment