Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start fish shell with different config folder

Tags:

shell

fish

Is it possible to start fish shell to point to another config directory, then the default ~/.config/fish?

I am trying to have same-behaving shell experience in multi-user system across different users (eq. while sudo -u <user> fish have the same aliases/functions etc. like under my user). But also have this in non-persistant way as other users in the system might not be interested in my settings.

So far my ideas were:

  1. source my config ==> problem with auto-load functions not available (eq. ~/.config/fish/functions/)
  2. symlink my config dir ==> not a non-persistant, but so far closest functional solution
like image 384
AuHau Avatar asked Jul 30 '26 19:07

AuHau


2 Answers

It's clear from your comments to the answer provided by Glenn that your original question left out some important information. If you're working on a system that has other users that will also sudo -u $some_user you should not symlink to your personal config files. Instead just leverage the fact that fish is compliant with the XDG Base Directory specification. Simply set env var XDG_CONFIG_HOME to your real home dir before starting fish. For example,

sudo -u $some_user /bin/sh -c "XDG_CONFIG_HOME=$HOME/.config fish"
like image 168
Kurtis Rader Avatar answered Aug 02 '26 04:08

Kurtis Rader


You could put all the common stuff in a common directory, perhaps

/opt/fish_config/config.fish
/opt/fish_config/functions/
/opt/fish_config/completions/

Then in any ~/.config/fish/config.fish you can put:

source /opt/fish_config/config.fish

and in /opt/fish_config/config.fish, in addition to your own fish stuff, be sure to add:

set fish_function_path $fish_function_path /opt/fish_config/functions
set fish_complete_path $fish_complete_path /opt/fish_config/completions

Just using a symlink is probably easier, although file permissions might be an issue.

Personally, although I don't share my config across multiple users on the same machine, I share my config across multiple machines: my fish config is in git, and I symlink ~/.config/fish to the git directory.

like image 43
glenn jackman Avatar answered Aug 02 '26 03:08

glenn jackman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!