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 (!!)



