Hacker News new | ask | show | jobs
by philjr 3318 days ago
Bringing this on a small tangent, but I've never been comfortable with 'sudo !!' and I can't really articulate why aside from wanting to be as explicit as possible.

<up>, <ctrl-a>, type sudo and enter is nearly as quick and much more explicit for me.

4 comments

If you are a long time "vi" user, put `set -o vi` in "~/.bashrc": the sequence to issue the previous command with sudo prepended will be <esc>0isudo<enter>, probably something that is in your muscle memory already.
While I'm a very long time vi user, and I'm completely at home with the keybindings, I could never get into using "set -o vi". For me it falls into the uncanny valley of being quite like vi while not actually being vi.
Both bash and zsh have the option histverify that will expand the !! like so:

> echo "Test"

> sudo !!<enter>

> sudo echo "Test"

You can then modify the command if you want to.

My zsh is set up (don't know if this is a default or not; I'm using Oh My Zsh) to not run the command if you use any history expansions in a command, instead it'll give you a new prompt line with the substitutions already filled in. That way you can check that the command is correct before running it.
Also <ctrl-p> instead of <up> for extra touchtype points.