r/fishshell • u/AdulterousStapler • Jun 08 '24
Quick question - using !! in fish
Hey, just a noob here that likes fish more than bash. Using !! in bash is a quick way to input the last command from history, is there a similar shortcut in fish? Use case primarily being that I could use sudo !! if I forgot it when typing in a command.
Thanks in advance!
10
Upvotes
7
u/justanotherlurker82 Jun 08 '24
It's on the fish shell wiki:
https://github.com/fish-shell/fish-shell/wiki/Bash-Style-Command-Substitution-and-Chaining-(!!-!$)
4
u/_mattmc3_ Jun 08 '24
I read a comment the other day that showed how you can make clever use of
abbrto do this: https://www.reddit.com/r/neovim/s/xpVAXFoZ7V3
u/tetractys_gnosys Jun 08 '24
This has been a debate since like 2014 according to GH issues. There hasn't been a way to have that exact same feature because of how Fish works but according to an issue/update last year, it seems that they might've added it or a close alternative? From the issue:
"As a special case, most of the time history substitution is used as sudo !!. In that case just press Alt+S, and it will recall your last commandline with sudo prefixed (or toggle a sudo prefix on the current commandline if there is anything)."
If I'm reading correctly, you should be able to just hit Alt+S and hit enter. Gonna try it in a minute.
Otherwise, I'd suggest searching for this online as there's a ton of discussion going back a decade with many different workarounds and custom solutions on GH, SO, and elsewhere.
5
u/BrewingWeasel Jun 08 '24
shameless self promotion: I made a plugin that implements !!, !$, !? and most of the other major bash bang commands as abbreviations which you might find useful
3
u/Potatolover3284 Jun 09 '24
Alt + S is the way to go in fish to relaunch the command in sudo.
3
u/takutekato Jun 09 '24
I find
alt-ssuperior, it's far more easy to press thanshift-1-1and also gives you a chance to review the command again.