You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the nice things of fish is that we don't have anything as complicated as the bash man page's "INVOCATION" section in our documentation.
"If it's a non-interactive shell, it does not read bashrc, except when it has been invoked by ssh or rshd, unless it is invoked as sh".
We always read config.fish, and that's nice.
However, as we see in e.g. #5246 and #4432, doing that even when non-interactive can cause some issues. Issues that we currently expect the user to expect, and guard against with if status is-interactive.
And I'm not really sure if configuration of non-interactive shells is ever really wanted? If you execute a script via fish /path/to/script (or directly via the shebang), you expect a consistent environment.
So, I would argue that we should possibly change this:
Don't source /etc/fish/config.fish and ~/.config/fish/config.fish (the one in /usr can stay, but that's not really "config")
Don't read snippets (which are technically in /usr/share/fish/config.fish)
Don't add the user's functions (in $HOME and /etc) to $fish_function_path
Now, obviously this complicates the logic a bit. It's "if fish is interactive, read config.fish, if not, don't" instead of just "read config.fish". I'd argue that it's still quite simple, and helps unbreak things that are currently quite easy to break - understanding that stty touches the terminal is advanced stuff.
Additonally, if configuration of non-interactive shells is wanted (and I don't see how, given that bash doesn't have it), we could add a "config-noninteractive.fish", or simply expect users to run fish -C 'source ~/.config/fish/config.fish.
Reacted by Chris Watkins, Adonis Kakoulidis, Robert Ford, philip, Alex Viscreanu, Lucas Garron, Jerry Ling, Myned, Demian Ferreiro, Jan Möller and 12 more
Reacted by Firegem, Shea690901, Nigel Baillie and thomas-fritz-hexagon
I'm against this. I do have stuff in my non-interactive startup config (path editing dependent on machine, for example), and I use my custom functions from non-interactive mode all the time.
Reacted by Jorge Bucaran, Paul Miu, A2, Konrad Gądek, Shea690901, Noel, kat and thomas-fritz-hexagon
I do have stuff in my non-interactive startup config (path editing dependent on machine, for example)
Could you provide some more detail?
Like I said, it's possible that non-interactive configuration is needed, I just believe that the default is backwards. Most configuration should not apply to non-interactive shells, and the current solution is a footgun.
path editing dependent on machine
You mean $PATH? Shouldn't that be done once in the login shell and then passed down? Or in e.g. pam_env? (There's a bit of an annoyance here in that much of linux expects a shell to run in the startup path, and specifically one that can read /etc/profile* - but fish can't do that to begin with)
I use my custom functions from non-interactive mode all the time.
That's the one I was least sure about. Do users expect functions to be available? They aren't as much of an issue as the configuration is (autoloading prevents them from doing stuff to the terminal in the startup path, unless that calls them), so it might also be okay to leave $fish_function_path unchanged.
Though that of course means it's different between interactive and non-interactive shells if your configuration changes $fish_function_path (mine does, but explicitly for interactive shells).
I'm against this too for the reason given in the intro. If we don't source config.fish, then we will get requests for how to configure fish in non-interactive mode, and there will be pressure to add a non-interactive config file, and then we're well on the road to bash.
It's true that surprising consequences erupt when configs designed for interactive mode are sourced in non-interactive mode. I believe it's worth tolerating this to maintain the simple initialization story.
Now there exists a function __fish_config_interactive, and it seems OK for it to invoke a function fish_user_config_interactive or similar. We can then document that interactive-only configs should go in this function. That seems better to me: when initialization happens in fish script then it is easier for users to inspect and understand.
Reacted by David Adam, Jorge Bucaran, Paul Miu, Firegem, Shea690901, kat and thomas-fritz-hexagon
it seems OK for it to invoke a function fish_user_config_interactive or similar.
That doesn't seem much better than if status is-interactive.
Plus, the problem I see is really one of defaults. Currently, everything in the config is executed in non-interactive fish by default. You need to do things to stop that from happening. So you need to do things in the majority of cases, even if you don't even know that you need to do things.
That's because this is necessary if we expect fish to be used via shebanged scripts.
And in that case, a commandline option to fish doesn't work, because fish might be opened via /usr/bin/env, and linux doesn't split any arguments beyond the first - so #!/usr/bin/env fish --no-config would try to open a file called fish --no-config.
If never reading config.fish for non-interactive shells is unacceptable, there are other ideas we could talk about, including:
Use config-noninteractive.fish if that exists instead of config.fish, so users can touch it to remove their customization from non-interactive mode
Allow config-interactive.fish so users can use that
Use config-noninteractive.fish in non-interactive mode, so users have to add source config.fish to that to enable the same customizations in non-interactive mode
(these would also include setting $fish_function_path and reading snippets - so we'd have to add a bit to read the snippets to the third option)
I realize that this complicates our startup logic a bit, but I don't think it's much, and I feel it's worth it. We're not adding 5 legacy paths to check, we're not differentiating login shells, but interactive and non-interactive shells are just quite different things.
I think it's a great default that fish -c foo behaves just like interactive foo.
Sane config.fish/functions/snippets should not break reasonable scripts, but I guess script authors don't want to rely on that..
And in that case, a commandline option to fish doesn't work, because fish might be opened via /usr/bin/env, and linux doesn't split any arguments beyond the first - so #!/usr/bin/env fish --no-config would try to open a file called fish --no-config.
The -S (split-string) option to env should be available, right?
The -S (split-string) option to env should be available, right?
Not in Posix and... basically nobody uses it, or thinks of using it? Even if people figured that fish --norc should be used (they most likely won't), the chance of somebody finding env -S is not good.
So for portable scripts it's out (discounting of course that /usr/bin/env is technically not even guaranteed to be the path to env, but I have zero sympathy for systems that don't have that).
Sane config.fish/functions/snippets should not break reasonable scripts, but I guess script authors don't want to rely on that..
Most people don't think of non-interactive scripts when configuring their shell for interactive use. We've had people make a test function and not notice it for a bit. Making e.g. a grep alias that does --color=always would be even harder to find.
Also plenty of configurations just do some slow interactive setup, and that's just wasteful and makes fish for scripts appear worse.
Basically it's needless footguns, is my position.
(Also, weirdly enough keychain states "Currently, keychain is not compatible with Fish shell.")
Reacted by David Adam, Georg Rollinger-Tertulino, Aurelio Jargas, Chris Watkins, Adonis Kakoulidis, Robert Ford, Demian Ferreiro, George Tsiamasiotis and Demorome
I just stumbled across this and have to say, I would be in hard favour of not sourcing config.fish whenever fish is launched non-interactively. The way it is now, it is very hard to write scripts that can be shared in any way because you'd always have to accomodate for potential quirks in some user's config. This effectively makes fish script useless as a general scripting language for anything other than customising your own shell.
If you really need one or two of your functions in your personal scripts, couldn't you just source those functions from within the script and then run them? Not very elegant, I admit, but that script is designed to be used by noone but yourself anyway.
Reacted by Aurelio Jargas, Andrej Resanovic, Zane Shelby, johanfo, ftjfo, Chris Watkins, Max Schillinger, Robert Ford, Edwin Kofler, Lucas Garron and 5 more
Reacted by Andrej Resanovic, johanfo, Robert Ford, Edwin Kofler, Demorome and Ilan-Sperber
typically symlinked to fish and if it is called like that, skip config?
I think the current default loading the system config is fine. And I would always assume someone willing to write portable scripts to go an extra mile in the documentation to find such a quirk. Ensuring portability is hard anyways because shell scripts rely so heavily on external programs and their expected behavior.
Reacted by Johannes Altmanninger, Lucas Garron, kxmh42 and Jacob Chapman
I recently ran into this issue. I'm amazed I didn't think of status is-interactive until reading this thread, I was doing all sorts of contortions to avoid loading stuff.
I think that non-interactive fish should still load the config by default, but that there should be a fish flag to load any directory or none at all.
Just ran into this today. I had an environment variable in my ~/.config/fish/config.fish that was overriding an environment variable I had manually set; definitely unexpected behavior. IF someone actually wanted to source config.fish all they'd have to do is
#!/usr/bin/env fish
source $__fish_config/config.fish
Nonetheless, I now have at the top of my config.fish
I ran into this issue in a GitHub codespace with fish 3.6.1.
#!/usr/bin/env fish does not load config.fish on macOS, and I don't recall it doing so in codespaces in the past. But it's doing so now!
And in that case, a commandline option to fish doesn't work, because fish might be opened via /usr/bin/env, and linux doesn't split any arguments beyond the first - so #!/usr/bin/env fish --no-config would try to open a file called fish --no-config.
The -S (split-string) option to env should be available, right?
This workaround seems to work for me for now.
I've written shell scripts for a long time now and never knew about that caveat, so this sure seems extremely non-obvious.
But these scripts are not supposed to load config.fish, so the status --is-interactive workaround would be insufficient if anyone else ever used them.
I guess I'm fine with this, but is there a good explanation for why /usr/bin/env fish doesn't seem to load config.fish on macOS? Any reason I should not expect this to be consistent across POSIX-like systems?
Those last three lines will tell you exactly which files it ran. If it did, check the files to see if you have a status is-interactive in there somewhere.
Looks like it was always (unintentionally) loading config.fish on macOS as well as codespaces. It's not until recently that something in Codespaces changed so that config.fish would print something for me! 😳
> FISH_DEBUG=config git-distance origin/main
config: exec_path: '/opt/homebrew/Cellar/fish/3.6.1/bin/fish', argv[0]: 'fish'
config: Using compiled in paths:
config: determine_config_directory_paths() results:
paths.data: /opt/homebrew/Cellar/fish/3.6.1/share/fish
paths.sysconf: /opt/homebrew/etc/fish
paths.doc: /opt/homebrew/Cellar/fish/3.6.1/share/doc/fish
paths.bin: /opt/homebrew/Cellar/fish/3.6.1/bin
config: sourcing /opt/homebrew/Cellar/fish/3.6.1/share/fish/config.fish
config: sourcing /opt/homebrew/etc/fish/config.fish
config: sourcing /Users/lgarron/.config/fish/config.fish
WARNING: Loaded `config.fish` outside an interactive shell.
0 commit(s) on main
0 commit(s) on origin/main
I wanted to ask if the discussion on this topic is ongoing? There are numerous proposed solutions here, but as it is a fish script isn't useful outside one's own setup unless they do weird complicated things to their configs or symlinks that make the current setup more complex than using a bash script. I have used bash scripts to make custom commands for a while, and used other people's, and I've greatly enjoyed being able to use a bash script as an executable. Currently, fish just can't work for a portable executable.
I think this is a big loss also, that greatly limits what fish is as a shell. I'd like to further add that fish aims at being user friendly, but I cannot look at a fish script and know what it might do. I have personally found fish to be great for interactive use, but less user friendly as a scripting language only because of this issue.
Activity
zanchey commentedon Dec 8, 2018
I'm against this. I do have stuff in my non-interactive startup config (path editing dependent on machine, for example), and I use my custom functions from non-interactive mode all the time.
faho commentedon Dec 8, 2018
Could you provide some more detail?
Like I said, it's possible that non-interactive configuration is needed, I just believe that the default is backwards. Most configuration should not apply to non-interactive shells, and the current solution is a footgun.
You mean $PATH? Shouldn't that be done once in the login shell and then passed down? Or in e.g. pam_env? (There's a bit of an annoyance here in that much of linux expects a shell to run in the startup path, and specifically one that can read /etc/profile* - but fish can't do that to begin with)
That's the one I was least sure about. Do users expect functions to be available? They aren't as much of an issue as the configuration is (autoloading prevents them from doing stuff to the terminal in the startup path, unless that calls them), so it might also be okay to leave $fish_function_path unchanged.
Though that of course means it's different between interactive and non-interactive shells if your configuration changes $fish_function_path (mine does, but explicitly for interactive shells).
ridiculousfish commentedon Dec 11, 2018
I'm against this too for the reason given in the intro. If we don't source config.fish, then we will get requests for how to configure fish in non-interactive mode, and there will be pressure to add a non-interactive config file, and then we're well on the road to bash.
It's true that surprising consequences erupt when configs designed for interactive mode are sourced in non-interactive mode. I believe it's worth tolerating this to maintain the simple initialization story.
Now there exists a function
__fish_config_interactive, and it seems OK for it to invoke a functionfish_user_config_interactiveor similar. We can then document that interactive-only configs should go in this function. That seems better to me: when initialization happens in fish script then it is easier for users to inspect and understand.faho commentedon Dec 11, 2018
That doesn't seem much better than
if status is-interactive.Plus, the problem I see is really one of defaults. Currently, everything in the config is executed in non-interactive fish by default. You need to do things to stop that from happening. So you need to do things in the majority of cases, even if you don't even know that you need to do things.
I'd like to figure out a way to turn that around.
mqudsi commentedon Dec 17, 2018
See also #5417 which is at least gives the user the option of explicitly opting out of loading
config.fish.faho commentedon Dec 30, 2019
So I'd like to get back to this.
That's because this is necessary if we expect fish to be used via shebanged scripts.
And in that case, a commandline option to fish doesn't work, because fish might be opened via /usr/bin/env, and linux doesn't split any arguments beyond the first - so
#!/usr/bin/env fish --no-configwould try to open a file calledfish --no-config.If never reading config.fish for non-interactive shells is unacceptable, there are other ideas we could talk about, including:
touchit to remove their customization from non-interactive modesource config.fishto that to enable the same customizations in non-interactive mode(these would also include setting $fish_function_path and reading snippets - so we'd have to add a bit to read the snippets to the third option)
I realize that this complicates our startup logic a bit, but I don't think it's much, and I feel it's worth it. We're not adding 5 legacy paths to check, we're not differentiating login shells, but interactive and non-interactive shells are just quite different things.
zanchey commentedon Jan 2, 2020
For example:
pam_env(not available)krobelus commentedon Jan 2, 2020
I think it's a great default that
fish -c foobehaves just like interactivefoo.Sane
config.fish/functions/snippets should not break reasonable scripts, but I guess script authors don't want to rely on that..The
-S(split-string) option toenvshould be available, right?faho commentedon Jan 2, 2020
Not in Posix and... basically nobody uses it, or thinks of using it? Even if people figured that
fish --norcshould be used (they most likely won't), the chance of somebody findingenv -Sis not good.So for portable scripts it's out (discounting of course that /usr/bin/env is technically not even guaranteed to be the path to env, but I have zero sympathy for systems that don't have that).
Most people don't think of non-interactive scripts when configuring their shell for interactive use. We've had people make a
testfunction and not notice it for a bit. Making e.g. agrepalias that does--color=alwayswould be even harder to find.Also plenty of configurations just do some slow interactive setup, and that's just wasteful and makes fish for scripts appear worse.
Basically it's needless footguns, is my position.
(Also, weirdly enough keychain states "Currently, keychain is not compatible with Fish shell.")
RealFerdinandDeSaussure commentedon Mar 1, 2020
I just stumbled across this and have to say, I would be in hard favour of not sourcing config.fish whenever fish is launched non-interactively. The way it is now, it is very hard to write scripts that can be shared in any way because you'd always have to accomodate for potential quirks in some user's config. This effectively makes fish script useless as a general scripting language for anything other than customising your own shell.
If you really need one or two of your functions in your personal scripts, couldn't you just source those functions from within the script and then run them? Not very elegant, I admit, but that script is designed to be used by noone but yourself anyway.
Korkman commentedon May 10, 2020
How about a custom she-bang
typically symlinked to fish and if it is called like that, skip config?
I think the current default loading the system config is fine. And I would always assume someone willing to write portable scripts to go an extra mile in the documentation to find such a quirk. Ensuring portability is hard anyways because shell scripts rely so heavily on external programs and their expected behavior.
IlanCosman commentedon Aug 14, 2020
I recently ran into this issue. I'm amazed I didn't think of
status is-interactiveuntil reading this thread, I was doing all sorts of contortions to avoid loading stuff.I think that non-interactive
fishshould still load the config by default, but that there should be afishflag to load any directory or none at all.fish: Apply my custom config only in interactive shells
8 remaining items
realmazharhussain commentedon Jun 13, 2021
madprops commentedon Nov 23, 2021
faho commentedon Nov 23, 2021
philn128 commentedon Jan 7, 2022
Just ran into this today. I had an environment variable in my
~/.config/fish/config.fishthat was overriding an environment variable I had manually set; definitely unexpected behavior. IF someone actually wanted to sourceconfig.fishall they'd have to do isNonetheless, I now have at the top of my
config.fishso I suppose this issue is benign.
lgarron commentedon Sep 28, 2023
I ran into this issue in a GitHub codespace with
fish3.6.1.#!/usr/bin/env fishdoes not loadconfig.fishon macOS, and I don't recall it doing so in codespaces in the past. But it's doing so now!This workaround seems to work for me for now.
I've written shell scripts for a long time now and never knew about that caveat, so this sure seems extremely non-obvious.
But these scripts are not supposed to load
config.fish, so thestatus --is-interactiveworkaround would be insufficient if anyone else ever used them.I guess I'm fine with this, but is there a good explanation for why
/usr/bin/env fishdoesn't seem to loadconfig.fishon macOS? Any reason I should not expect this to be consistent across POSIX-like systems?Adjust `fish` shebang to explicitly avoid loading `config.fish`.
lgarron commentedon Sep 28, 2023
In fact, seems like this is so non-obvious that none of the
fishshell scripts in this repo do it:https://github.com/search?q=repo%3Afish-shell%2Ffish-shell+%2F%23%21%5C%2Fusr%5C%2Fbin%5C%2Fenv.*fish%2F&type=code
Adjust `fish` shebang to explicitly avoid loading `config.fish`.
faho commentedon Sep 28, 2023
They can't do it because
envmight not have a-Soption.It's not just that it's non-obvious, it's that there is no portable way to do it.
It should, I don't know why it wouldn't. Maybe $XDG_CONFIG_HOME is set to something in that context?
lgarron commentedon Sep 28, 2023
Ah, I see. It would definitely be very useful to have a portable option.
Looks like it's empty. 🤷♀️
faho commentedon Sep 28, 2023
Try setting $FISH_DEBUG to "config" and then run the file. E.g.
This will print output like:
Those last three lines will tell you exactly which files it ran. If it did, check the files to see if you have a
status is-interactivein there somewhere.[config.fish] Print a warning when we're unexpectedly in an interacti…
lgarron commentedon Sep 28, 2023
Aha, thanks!
Looks like it was always (unintentionally) loading
config.fishon macOS as well as codespaces. It's not until recently that something in Codespaces changed so thatconfig.fishwould print something for me! 😳Load Fish plugins only when shell is interactive
Ilan-Sperber commentedon Oct 5, 2026
I wanted to ask if the discussion on this topic is ongoing? There are numerous proposed solutions here, but as it is a fish script isn't useful outside one's own setup unless they do weird complicated things to their configs or symlinks that make the current setup more complex than using a bash script. I have used bash scripts to make custom commands for a while, and used other people's, and I've greatly enjoyed being able to use a bash script as an executable. Currently, fish just can't work for a portable executable.
I think this is a big loss also, that greatly limits what fish is as a shell. I'd like to further add that fish aims at being user friendly, but I cannot look at a fish script and know what it might do. I have personally found fish to be great for interactive use, but less user friendly as a scripting language only because of this issue.