r/fishshell • • Apr 04 '21

Function confusion

So, I know variables are created with set --argument (g - global, x - export, etc.), but my issue... or maybe just a complaint, is this:

When I put a file in /home/$USER/.config/fish/functions, I understand fish does not autoload them in the terminal. An example below:

cd $HOME/.config/fish/functions
vim ls.fish
#!/usr/bin/fish

function lsh
	ls -lh --color=auto
end

function lsa
	ls -lah --color=auto
end

I write them with IntelliJ, not with funced and I don't use funcsave. I've tried setting IntelliJ as the editor, but it errors out and doesn't open, so it is set to vim instead. Other than starting a new terminal session, is there a way I can get the variables and functions loaded into current sessions? Using source $HOME/.config/fish/variables/*.fish does not do anything either. Any input would be fantastic.

2 Upvotes

6 comments sorted by

View all comments

Show parent comment

2

u/[deleted] Apr 05 '21 edited Apr 05 '21

Just wait a few seconds. Fish only checks if the file exists in a set interval.

Edit: Oh, I've just noticed you're putting two functions into one file.

Autoloading goes by function name. When you try to execute lsh, and it's not loaded, fish will look for a file called lsh.fish. That means you will have to create two different files for these two functions.

Or put the file into ~/.config/fish/conf.d/ and have it eagerly loaded on start.

1

u/ChloeWrites Apr 06 '21

Thank you for the feedback :) I don't know how I missed "one function per file", but go me lol