Skip to content

Instantly share code, notes, and snippets.



Forked from cmlsharp/!!
Last active Dec 23, 2019
What would you like to do?
# Add this to your ~/.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]
eval /usr/bin/sudo $argv

This comment has been minimized.

Copy link

@cmlsharp cmlsharp 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


This comment has been minimized.

Copy link

@tuxitop tuxitop commented Oct 26, 2015

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


This comment has been minimized.

Copy link

@OJFord 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
You can’t perform that action at this time.