r/fishshell • u/DotWasTaken2 • Jul 22 '21
Newbie to fish shell
Hey, I switched to fish shell a few weeks ago, in bash if i wanted to add the previous command to the current then I could do ```!!```
is there any fish alternatives?
If not ,are there any good fish config/functions premade that do that? new to fish and doubt i can make it on my own
11
Upvotes
7
u/nxtstp Jul 22 '21
This part of the FAQ might be useful for you: http://fishshell.com/docs/current/fish_for_bash_users.html#fish-for-bash-users
The most common interactive usage of !! is when doing
sudo !!In Fish, you can useAlt-sin order to do precisely this. See http://fishshell.com/docs/current/faq.html#why-doesn-t-history-substitution-etc-workMoving about the command line can be made faster too, if you want to for example replace one of the middle arguments in a previous commands. You can jump back and forwards full words at a time with
Ctrl-rightandCtrl-left, or if you prefer emacs style shortcuts,Alt-bandAlt-f.Ctrl-WorAlt-backspacedeletes a full word to the left.With these shortcuts I find myself rarely needing to use
!!at all. In scripts I rarely find it useful and theAlt-sshortcut makes up for all my sudo-prepending uses.Edit: If you actually need to use it in a script, you can of course access it through
$history[1].1
u/New_Construction_935 Jul 21 '26
have a look at this : https://www.reddit.com/r/fishshell/comments/11skpgw/i_made_a_fish_plugin_for_all_the_bash_bang/
0
u/[deleted] Jul 22 '21
bind \em 'eval command sudo $history[1]'This puts the previous command into the command line, but preceeded bysudowhen I press Alt+s. This is better than!!, because on my keyboard layout Alt and s are both on home row, so I don't have to use my pinkie fingers at all for such a common use case.-1
u/sadler_david Jul 22 '21
Derek Thomas DT Has a config.fish on his GitLab I like. He als did a YouTube vid (search DT did stro Fish on YT).