Skip to content

Instantly share code, notes, and snippets.

@erithmetic
Created January 12, 2010 03:59
Show Gist options
  • Save erithmetic/274886 to your computer and use it in GitHub Desktop.
Save erithmetic/274886 to your computer and use it in GitHub Desktop.
Command to run the last command as a sudo command
#!/bin/bash
#
# Wish you had just run the last command as sudo? sudoh will do it!
#
# INSTALLATION
#
# On Mac OS X, add the following to your ~/.bash_profile:
# shopt -s histappend
# export PROMPT_COMMAND='history -a'
# export HISTIGNORE="sudoh"
#
# Then run:
# curl http://gist.github.com/raw/274886/cbdf5148a2b4aec69e08884599252195942e6680/sudoh -O
# sudo mv sudoh /usr/local/bin/sudoh
# sudo chmod +x /usr/local/bin/sudoh
hist_item=`tail -n 1 ~/.bash_history`
echo "SUDO $hist_item"
echo $hist_item | xargs sudo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment