-
-
Save b-/981892a65837ab0a387e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
testing for $argv[1] would be more specific, and it also fixes a bug.
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
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