Instantly share code, notes, and snippets.

@b- /!! forked from crossroads1112/!!
Last active Jun 21, 2017

Embed
What would you like to do?
# Add this to your ~/.config/fish/config.fish
# Syntax:
# To just rerun your last command, simply type '!!'
# This forked version supports "sudo !!" via two functions.
function !!
eval $history[1] $argv
end function
function sudo
if test $argv
if test $argv = "!!"
eval /usr/bin/sudo $history[1]
else
eval /usr/bin/sudo $argv
end
end
end
@crossroads1112

This comment has been minimized.

crossroads1112 commented Aug 30, 2014

I like this! This works much better than my original function other than mine was slightly more flexible in that I could easily add more terms that were to be prepended to the previous command. However, this is much cleaner. Kudos

@tuxitop

This comment has been minimized.

tuxitop commented Oct 26, 2015

testing for $argv[1] would be more specific, and it also fixes a bug.

@OJFord

This comment has been minimized.

OJFord commented May 15, 2016

Would be a good idea to modify the command in history, replacing !! with the original command.

As it stands:

~> echo ''

~> !!

~> sudo !!
sudo: !!: command not found

A more realistic case when this might occur would be repeated execution of the last command - if you can only do it once then you'd be better off with up+return in your muscle memory than use this !! function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment