How can I make aliases defined in ~/.config/fish/config.fish
and functions defined in ~/.config/fish/functions
available for the root user as well?
symlinking to /root/.config/fish
didn't do the job. Furthermore, I'd also like to be able to use my functions and aliases via sudo
, which is currently not working as well.
How do you guys do that?
I don't have a solution for the first problem (I don't have any functions that are useful for the root user), but the second one (functions not working as an argument for sudo
) can be solved with a wrapper function:
function sudo
if functions -q $argv[1]
set argv fish -c "$argv"
end
command sudo $argv
end
The issue is of course that sudo
is an external command (usually at /usr/bin/sudo) that cannot know about fish internals like function definitions. So this wrapper will call fish if you give it a function name. Of course, since this launches a new fish session, some things, like cd
will not be useful because it won't alter the state of the main fish session.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With