How to add exports to fish like in .bashrc?

I just wanted to be able to add inside some fish configuration file (don't know which/where) the same function as this:

export PERL5LIB=/home/iaco/workspace/perl:/home/iaco/devtools

This line was added inside the .bashrc file and it was able to export the variable each time I opened a terminal.

Is there something like that for fish? I know that I can export variables in fish using the "set" command, but I want to modify one file (don't know which one) in order to automatically add those variables each time I open a fish terminal.


Solution 1:

You can put the user-specific fish configuration, including set directives, in ~/.config/fish/config.fish. The contents should look more or less like that

set -x PERL5LIB /home/iaco/workspace/perl:/home/iaco/devtools

More information can be found in the documentation.

Solution 2:

Use universal variables introduced in fish 2.0.0. -x means exported, and -U means that it's declared for every fish session. You can also use the long options --export and --universal.

set -xU PERL5LIB /home/iaco/workspace/perl:/home/iaco/devtools

Please note that PATH variable is a bit of a special case. While PATH can be universally changed, this will affect your current PATH variable (which may be a bit of a problem if an extra path will be introduced by an operating system). For PATH variable, use fish_user_paths variable (which only adds paths) instead. The variable is an array, which means you don't have to put : characters.

set -U fish_user_paths /home/iaco/workspace/perl/share/bin /home/iaco/bin $fish_user_paths