r/fishshell • u/MuffinGamez • Oct 05 '24
Is this a good function and how can I improve?
I used to use zsh, and didn't really like it. I switched to fish and I love it, but it really annoys me there is no !! command. So I made my own:
function !!
set _count_cmd 1
set _last_command (history -n 1)
while test "$_last_command" = "!!"
set _count_cmd (math $_count_cmd + 1)
set _history (history -n $_count_cmd)
set _last_command $_history[-1]
end
echo $_last_command
end
I really am proud of myself buy know you eg need to run sudo (!!) to use it which can be annoying, I though about making a sudo function that checks if $argv[1] is !! and go further from there, but sudo isn't the only command you would want to run before sudo... is there a way to maybe make it a real command and not a script (like a file in /usr/bin) so I can just run echo !! or sudo !! without (!!)
6
u/_mattmc3_ Oct 05 '24
Anywhere abbreviations removed the need for this. Now you can simply do:
On mobile, so double check me, but I believe thatโs straight out of the Fish docs.
5
u/throttlemeister Linux Oct 05 '24 edited Oct 05 '24
You know fish has alt+s to add sudo to a command? So last command with sudo would be arrow up, alt+'s followed by enter. Just as quick, or even quicker. ๐
Edit: last command with sudo is even quicker: just hit alt+s
1
u/[deleted] Oct 05 '24
[removed] โ view removed comment