Skip to content

Read /etc/profile.d/*.fish at startup? #1956

Closed

Description

@amluto

I have a request from some other Fedora folks to allow fish configuration snippets (e.g. ccache configuration) in /etc/profile.d/*.fish. Would this make sense as default behavior in upstream fish (via /usr/share/fish/config.fish perhaps)?

Activity

  1. zanchey commented on Feb 24, 2015

    @zanchey
    Member

    LSB section 16.2 requires the use of /etc/profile.d/*.sh, although the behaviour is not specified for *.fish scripts. Does this directory exist on OS X at all?

    There was a similar intention behind /usr/share/fish/vendor-completions.d, and I think it's better done in the /usr/share hierarchy, but profile.d might be a special case.

  2. amluto commented on Feb 24, 2015

    @amluto
    ContributorAuthor

    I would argue for something in /usr/share and /etc/profile.d/*.fish. The
    former is a much better place for distro scripts, sh tradition
    notwithstanding. The latter is good for admins to drop snippets.

    Fish isn't sh, so I think LSB barely applies.
    On Feb 23, 2015 7:26 PM, "David Adam" [email protected] wrote:

    LSB section 16.2
    http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/etc.html
    requires the use of /etc/profile.d/*.sh, although the behaviour is not
    specified for *.fish scripts. Does this directory exist on OS X at all?

    There was a similar intention behind /usr/share/fish/vendor-completions.d,
    and I think it's better done in the /usr/share hierarchy, but profile.d
    might be a special case.

    —
    Reply to this email directly or view it on GitHub
    #1956 (comment)
    .

  3. zanchey commented on Feb 24, 2015

    @zanchey
    Member

    Thinking about it, completions are a bit different to configuration snippets that are run for all users, and I think /etc/profile.d/*.fish would be a reasonable compromise as they may need to be overridden and thus treated as conffiles.

    Local administrators should drop snippets in /etc/fish/config.fish.

  4. rapgro commented on Feb 24, 2015

    @rapgro

    👍

  5. added this to the milestone on Mar 24, 2015
  6. ridiculousfish commented on Mar 24, 2015

    @ridiculousfish
    Member

    Simple. Tested with Ubuntu Precise.

  7. ridiculousfish commented on Mar 24, 2015

    @ridiculousfish
    Member

    Thanks for reporting this.

  8. added
    docs
    on Mar 25, 2015
  9. zanchey commented on Mar 25, 2015

    @zanchey
    Member

    Probably should use __fish_sysconfdir?

  10. zanchey commented on Mar 25, 2015

    @zanchey
    Member

    Actually, possibly not.

    Additionally - should profile.d/*.fish only be evaluated for interactive login shells, in line with the standard /etc/profile conventions? Or should all snippets call if status --is-login?

  11. ridiculousfish commented on Mar 25, 2015

    @ridiculousfish
    Member

    Good question - what do you think @amluto regarding zanchey's question about whether these should be run in non-interactive shells?

  12. rapgro commented on Mar 25, 2015

    @rapgro

    I am the reporter of the original downstream (Fedora) bug.

    From the LSB specification linked above:
    The sh utility shall read and execute commands in its current execution environment from all the shell scripts in this directory that have the suffix .sh when invoked as an interactive login shell, or if the -l (the letter ell) is specified (see Shell Invocation).

    So the answer is "yes" to "interactive login shell" only.

  13. zanchey commented on Mar 26, 2015

    @zanchey
    Member

    The downstream bug for those playing at home

    I'm still not convinced about using profile.d. Could it mislead people into thinking fish reads /etc/profile or any of the other Bourne initialisation files? Do we want to go down the road of having some files that get read sometimes and not others? I found that enormously confusing when starting out with bash and zsh:

    Commands are then read from $ZDOTDIR/.zshenv. If the shell is a login shell, commands are read from /etc/zsh/zprofile and then $ZDOTDIR/.zprofile. Then, if the shell is interactive, commands are read from /etc/zsh/zshrc and then $ZDOTDIR/.zshrc. Finally, if the shell is a login shell, /etc/zsh/zlogin and $ZDOTDIR/.zlogin are read.

    Before the advent of autoloading, fish used /etc/fish.d for this sort of thing - see the discussion from 2006. In keeping with the current pattern, that would now probably become $__fish_sysconfdir/config.d/ or something similar.

    I would appreciate perspectives from other packagers - @tianon @mithrandi ?

  14. 10 remaining items

  15. Darkshadow2 commented on Apr 14, 2015

    @Darkshadow2
    Contributor

    How about a directory in $__fish_sysconfdir that would work like profiles.d?

  16. zanchey commented on Sep 4, 2015

    @zanchey
    Member

    /etc/environment is another potential target.

  17. despairblue commented on Sep 13, 2015

    @despairblue

    What about vendor functions? Where would those go? Arch's autojump (this file) package puts it into /etc/profile.d/, which, of course, does not work.

  18. faho commented on Sep 14, 2015

    @faho
    Member

    My 2 cents:

    I'd like to step back from "profile.d" a bit here.
    As far as I can see, there are three groups of people we should satisfy with our configuration options:

    In particular, admins might wish to override upstream, and users might wish to override both admins and upstream. The admin should not need to touch the upstream directory because package managers (and the user should not have to touch the admin directory because... well, UNIX, privilege separation and all that). Every one of these groups should have their own directory.

    Apart from the three groups of people, we have three types of code they might want to add:

    • Functions
    • Completions
    • Event handlers and other code that can't be autoloaded (this is unless we can come up with a better solution to the autoloading problem - calling it "config" as a catch-all for configuration that doesn't fit into the other two is also possible)

    We already have the first two for users and fish itself, and I have proposed the third somewhere else already, but I can't come up with a good name for it.

    I don't consider /etc/profile.d a good solution because of the undefined behavior - we should not break other shells.


    So, now, with all that in mind, I propose the following solution:

    • Users get ~/.config/fish (replace with appropriate variable)
    • Admins get /etc/fish
    • Upstream gets /usr/share/fish/vendor_* (since vendor_completions.d already exists)
    • Every one of those gets subdirectories "completions", "functions" and "event" (final name TBD) (i.e. vendors/upstream get "/usr/share/fish/vendor_functions.d" and such)
    • The preference is User > Admin > Upstream > fish (not too sure about the latter two)
    • Completions and functions are autoloaded and named after the program they complete or function they provide, respectively, plus a ".fish" extension
    • "Event" files are all sourced at startup in lexical order (unless we find a different solution - naming after the event plus a suffix is also possible to allow for multiple upstreams hooking into the same event)

    What does everyone think of this idea?

  19. pickfire commented on Sep 15, 2015

    @pickfire
    Contributor

    Good idea, I didn't even thought about that.

  20. Profpatsch commented on Sep 15, 2015

    @Profpatsch

    For NixOS I thought about sourcing everything in a environment variable on startup.
    Stumbled over #2391 though.

  21. amluto commented on Sep 15, 2015

    @amluto
    ContributorAuthor

    I like this. I think that, if this happens, that fish should follow the
    sysctl / systemd model in which a file in ~/.config/fish/* that has the
    same name as a file in /usr/share/fish/* overrides it and that a symlink
    from ~/.config/fish/* to /dev/null suppresses a similarly named file in
    /usr/share/fish/*, etc.

    On Mon, Sep 14, 2015 at 1:01 PM, Fabian Homborg [email protected]
    wrote:

    My 2 cents:

    I'd like to step back from "profile.d" a bit here.
    As far as I can see, there are three groups of people we should satisfy
    with our configuration options:

    Upstream software developers or distributions wishing to hook into
    fish (like the pantheon people, see #1382
    #1382)

    Admins wishing to add configuration for all users

    Users wishing to add configuration

    In particular, admins might wish to override upstream, and users might
    wish to override both admins and upstream. The admin should not need to
    touch the upstream directory because package managers (and the user should
    not have to touch the admin directory because... well, UNIX, privilege
    separation and all that). Every one of these groups should have their own
    directory.

    Apart from the three groups of people, we have three types of code they
    might want to add:

    Functions

    Completions

    Event handlers and other code that can't be autoloaded (this is unless
    we can come up with a better solution to the autoloading problem - calling
    it "config" as a catch-all for configuration that doesn't fit into the
    other two is also possible)

    We already have the first two for users and fish itself, and I have
    proposed the third somewhere else already, but I can't come up with a good
    name for it.

    I don't consider /etc/profile.d a good solution because of the undefined

    behavior - we should not break other shells.

    So, now, with all that in mind, I propose the following solution:

    Users get ~/.config/fish (replace with appropriate variable)

    Admins get /etc/fish

    Upstream gets /usr/share/fish/vendor_* (since vendor_completions.d
    already exists)

    Every one of those gets subdirectories "completions", "functions" and
    "event" (final name TBD) (i.e. vendors/upstream get
    "/usr/share/fish/vendor_functions.d" and such)

    The preference is User > Admin > Upstream > fish (not too sure about
    the latter two)

    Completions and functions are autoloaded and named after the program
    they complete or function they provide, respectively, plus a ".fish"
    extension

    "Event" files are all sourced at startup in lexical order (unless we
    find a different solution - naming after the event plus a suffix is also
    possible to allow for multiple upstreams hooking into the same event)

    What does everyone think of this idea?

    —
    Reply to this email directly or view it on GitHub
    #1956 (comment)
    .

  22. faho commented on Sep 16, 2015

    @faho
    Member

    @amluto:

    That's basically what happens for autoloaded files already (probably not 100% the same, but close enough).

    For the eager-loading stuff this should be implemented as well, I agree.

  23. added a commit that references this issue on Oct 20, 2015
    91ea1ff
  24. self-assigned this
    on Dec 11, 2015
  25. ahti commented on Jan 11, 2016

    @ahti
    Contributor

    I like the suggestion by @faho, but there is one thing I think might be missing:

    You mentioned the subdirectories "completions", "functions" and "event". One thing /etc/profile.d is used for on Arch Linux (at least for the perl package) is adding directories to $PATH, and I don't see a subdirectory that this kind of behavior would fit into.

  26. faho commented on Jan 11, 2016

    @faho
    Member

    @ahti: Check #2498 - after my proposal, I noticed that the "event" directory can be used much more generally, so it's now called "conf.d".

    In essence that proposal includes three kinds of directories:

    • Completions - autoloaded
    • Functions - autoloaded
    • Configuration snippets - eagerly sourced

    extending $PATH would fall under the third category.

  27. ahti commented on Jan 11, 2016

    @ahti
    Contributor

    👍

  28. locked as resolved and limited conversation to collaborators on Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions