Skip to content

Document conf.d / config.fish sourcing order #3099

Closed

Description

The current implementation sources conf.d snippets before config.fish. I didn't notice this until @daenney pointed it out to me.

I think the config.fish should be the user's entry point, the very first thing that I have control over that runs before anything else.

For example, if a snippet depends on an env var I am setting in my config.fish, it won't be available as a result of the current execution order.

Activity

  1. faho commented on Jun 1, 2016

    @faho
    Member

    So, the thing is, if you source conf.d after config.fish, that means that

    • Snippets can depend on config.fish
    • config.fish can't override snippets

    If you do it the other way around, those two are going to be switched - config.fish can depend on snippets and override them, but snippets can't use config.fish stuff.

    The tough question here is: What is less painful? What occurs more often? That snippets depend on config.fish, or that someone wishes to override snippets? It seems no matter which you pick there'll be some weirdness.

    Then there's the issue that changing this would essentially require doing the snippets stuff in C++, since we don't have any script to hook it into (currently all stuff related to this is nicely encapsulated in share/config.fish).

    So: What was your original issue with this? How'd you try to use it?

  2. gretel commented on Jun 1, 2016

    @gretel

    i never really liked the idea of having a config.fish at all. how about

    • get rid of config.fish as a requirement
    • move the default to conf.d and have deprecation notice
    • change logic so conf.d/config.fish will be loaded first
      • if it exists
        • which is debatable because it'd be another exception, so i'd could be named 00_config.fish
  3. faho commented on Jun 1, 2016

    @faho
    Member

    get rid of config.fish as a requirement

    There is no config.fish requirement. You can move it over to conf.d if you so desire. I've just done so and it works.

    The current situation is arguably more painful, only because it makes it impossible or very hard to have a unique entry point to configure some stuff.

    No matter which order you pick, there is no "unique entry point". Either you configure something in config.fish and you don't see it because a snippet sets it (this would happen if config.fish before snippets, i.e. if we made this change), or you configure something in config.fish and a snippet can't use it (which is what happens now).

    I'm quite wary of making it harder to override something a snippet does, because they can come from a variety of sources and might do something the user doesn't want - e.g. I could get a new snippet when I update some system package.

    The only other thing I can come up with is making a "load-snippets" function that users can put into their ~/.config/fish/config.fish, and ship one that includes it by default.

  4. gretel commented on Jun 1, 2016

    @gretel

    @BRJ sure. but do rather propose solutions than backwards compatible changes 😸

    @faho removing it is user behaviour, not what results of a default installation

  5. daenney commented on Jun 1, 2016

    @daenney

    I've currently worked around it by having a conf.d/000-env.fish instead that does all the stuff I want to set up in my environment. It gets executed first and everything works. I think that as long as there's a good and documented way for people to achieve ordering of conf.d entries I would actually be pretty happy to get rid of config.fish entirely. It also makes splitting up, modularising and having your configuration in VCS easier.

    My current confusion stems from the fact that most shells have no concept of these kinds of snippets. As a consequence any behaviour like this basically comes down to sourcing the files in your .bashrc etc, allowing you to control order and avoiding surprises/ordering issues like these.

  6. faho commented on Jun 1, 2016

    @faho
    Member

    I think that as long as there's a good and documented way for people to achieve ordering of conf.d entries

    That we can do. Do you have any wording suggestions? This uses the same sort function our completions use, which is a "natural" sort - so "1" < "2" < "2_b" < "02" < "3".

  7. gretel commented on Jun 1, 2016

    @gretel

    @faho hum.. good question. natural sort seems fine but for something automatic it is less determinable. going to have a read on asciibetical https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/

  8. added
    docs
    on Jun 1, 2016
  9. daenney commented on Jun 2, 2016

    @daenney

    I'm not entirely sure what ordering to go for. The trick is to figure out what makes most sense when people are trying to debug why things aren't loading in the right order. When that happens I would personally prefer the order in which we process them to be more identical to what an ls -l or find . -type f would give me on that directory as that would make it more obvious in which order things happen and I wouldn't have to do the conversion between different sort orders myself. In both those cases the sort order is asciibetical, not natural.

    However, if I'm just trying to figure out the order of things that are getting executed in my head I would result to natural/alphabetical order in my mental model, not asciibetical.

    It's tricky.

  10. daenney commented on Jun 2, 2016

    @daenney

    With regards to the ordering of conf.d first and then config.fish I think @faho is right and that order needs to be kept as is.

    If we think about Fisherman plugins for example, when they ship configuration it all gets neatly loaded through conf.d snippets. However, if config.fish would get loaded first a plugin could override user defined behaviour and we'd take away the power of the user to fix that (though you could name a snippet in conf.d in such a way it would always get executed last). With config.fish being loaded last it can essentially function as a user's override file, without needing some explicit other mechanism or trickery to do so. It's only counter-intuitive because everyone's used to .bashrc and .zshrc and so on being the entrypoint for all configuration in the shell.

  11. faho commented on Jun 2, 2016

    @faho
    Member

    When that happens I would personally prefer the order in which we process them to be more identical to what an ls -l or find . -type f would give me on that directory

    It's the same order as globs (because that's where the sorting happens).

    Anyway, does anyone have any idea what the documentation should say? I'm struggling to come up with anything.

  12. daenney commented on Jun 2, 2016

    @daenney

    Perhaps something like:

    In most other shells the equivalent of config.fish would be the entrypoint where we start evaluating configuration. However in Fish config.fish gets evaluated last. This gives you the power to override behaviour or configuration that got added to your session by snippets in conf.d.

    The order by which snippets in conf.d get evaluated is based on the file names using X sort order. This means that in order to set environment variables or configuration that other snippets might depend on you need to ensure that snippet gets executed as early as possible. You can achieve this by using a filename along the lines of 0-env.fish as that will guarantee it is evaluated first.

    We should probably add an example or two about how the sort order works and how to fix things that aren't getting evaluated in the order the user expected.

  13. krader1961 commented on Jan 17, 2017

    @krader1961
    Contributor

    In most other shells the equivalent of config.fish would be the entrypoint where we start evaluating configuration.

    That is not true for any shell I've used in the past three decades. Certainly not sh, ksh, zsh, bash. From the bash man page:

    When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and exe- cutes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

  14. therealpxc commented on Mar 27, 2017

    @therealpxc

    On operating systems where one can't get by by just guessing what ought to be on the path in case it is empty, we're not talking about restricting plugin functionality just a little bit— we're talking about restricting plugins to the point that they can never call external programs. This will affect all operating systems where the OS needs to be able to set the PATH variable (or any other, like library path variables or path variables for interpreted languages or whatever) before programs can find each other. That seems to me to defeat the purpose of even having an OS-level configuration file for fish.

    If you go through with this plan, the only way to make fish plugins which dare to use even hostname or find work correctly on NixOS will be by patching $prefix/share/config.fish in the Fish source. And the thing is that it doesn't just break the plugins. The breakage can propagate to the whole shell, affecting login at every virtual console and preventing the display server from launching if the display manager service inherits its environment from the login shell.

    Or you could permanently add more path hacking to $prefix/share/config.fish like you currently do for Darwin. :-\

    I know having to implement this bit in the C++ code means generating more work for you and that my Linux distro is kind of marginal and non-standard. I hope I don't sound bratty here but this feels quite urgent for me because NixOS and fish are both part of trying to get the best Unix-like experience I can, even if it means having to take a little extra care and doing things a little differently sometimes. I hope that makes my case somewhat sympathetic.

  15. modified the milestones: , fish-future on Apr 10, 2017
  16. changed the title [-]Source user's config.fish before running conf.d snippets.[/-] [+]Document conf.d / config.fish sourcing order[/+] on Apr 10, 2017
  17. added a commit that references this issue on Apr 17, 2017
    cf948f5
  18. ranisalt commented on Jan 13, 2018

    @ranisalt
  19. hg42 commented on Nov 4, 2019

    @hg42
  20. locked as resolved and limited conversation to collaborators on Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions