Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

same aliases and functions for user and root in fish shell

Tags:

fish

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?

like image 264
Anton Harald Avatar asked Apr 11 '16 12:04

Anton Harald


1 Answers

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.

like image 101
faho Avatar answered Sep 23 '22 20:09

faho