Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fish shell automatic directory specific functions

Tags:

fish

Is it possible to have fish automatically load additional configurations based on the directory you are in? A possible example, but obviously this doesn't work. You navigate to a project folder:

cd ~/my_proj

There is a file in that folder called .fish.config that contains a special fish function that is now accessible (since we are in my_proj).

Is there any built-in mechanism in fish that allows the loading from some fish config file when navigating to a directory (similar to above)?

like image 430
Jono Avatar asked Oct 19 '25 13:10

Jono


2 Answers

Take a look at the --on-variable flag for the function statement. You can define a function like this that runs whenever the PWD changes:

function react_to_pwd --on-variable PWD
   echo Reacting to PWD changing to $PWD
end
like image 64
Kurtis Rader Avatar answered Oct 22 '25 05:10

Kurtis Rader


There is some pre-existing work in this area:

  • direnv
  • autoenv-fish
  • Automatically set environment variables based on working directory
like image 34
Zanchey Avatar answered Oct 22 '25 07:10

Zanchey



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!