What is the equivalent of bash's !$ and !! in the fish shell?
Alt-Up arrow gives you the last argument from the previous command. Subsequent pushes cycle throught prior arguments.
I haven't found a satisfactory equivalent to !!
, except Up then Ctrl-A
I found this perfect answer on the fish-users mailing list:
function bind_bang
switch (commandline -t)[-1]
case "!"
commandline -t $history[1]; commandline -f repaint
case "*"
commandline -i !
end
end
function bind_dollar
switch (commandline -t)[-1]
case "!"
commandline -t ""
commandline -f history-token-search-backward
case "*"
commandline -i '$'
end
end
function fish_user_key_bindings
bind ! bind_bang
bind '$' bind_dollar
end
Further discussion on fish's github wiki
sudo !! (or sudo bang bang) is one of my most oft used commands. I'm still using just plain old bash that has it just fine. Sorry to hear that fish doesn't implement it correctly. A little googling and I found this:
function sudo
if test "$argv" = !!
eval command sudo $history[1]
else
command sudo $argv
end
end
There are a lot more options over on the thread here: https://github.com/fish-shell/fish-shell/issues/288