Skip to main content
formatting
Source Link
Gilles 'SO- stop being evil'
  • 866.5k
  • 205
  • 1.8k
  • 2.3k

Nicest way I can do this is to make an autoloaded function, say sudo_r:

function sudo_r { typeset comm=$(hist -nl ${@sudo_r:- -1 -1} | sed 1q); print -- $comm; sudo $comm; }

function sudo_r { typeset comm=$(hist -nl ${@:- -1 -1} | sed 1q); print -- $comm; sudo $comm; } 

Then (say) "alias ss=sudo_r". When this is done, you can type "ss cp"ss cp to repeat the last command beginning with "cp"cp, but prefixing it with "sudo"sudo. Or if you type ss <carriage_return>ss Return, it will sudosudo the previous command.

Nicest way I can do this is to make an autoloaded function, say sudo_r:

function sudo_r { typeset comm=$(hist -nl ${@:- -1 -1} | sed 1q); print -- $comm; sudo $comm; }

Then (say) "alias ss=sudo_r". When this is done, you can type "ss cp" to repeat the last command beginning with "cp", but prefixing it with "sudo". Or if you type ss <carriage_return>, it will sudo the previous command.

Nicest way I can do this is to make an autoloaded function, say sudo_r:

function sudo_r { typeset comm=$(hist -nl ${@:- -1 -1} | sed 1q); print -- $comm; sudo $comm; } 

Then (say) "alias ss=sudo_r". When this is done, you can type ss cp to repeat the last command beginning with cp, but prefixing it with sudo. Or if you type ss Return, it will sudo the previous command.

Source Link

Nicest way I can do this is to make an autoloaded function, say sudo_r:

function sudo_r { typeset comm=$(hist -nl ${@:- -1 -1} | sed 1q); print -- $comm; sudo $comm; }

Then (say) "alias ss=sudo_r". When this is done, you can type "ss cp" to repeat the last command beginning with "cp", but prefixing it with "sudo". Or if you type ss <carriage_return>, it will sudo the previous command.