Skip to content

Remove default universal variables #7317

Closed

Description

@faho

Currently, we set a few universal variables on first run:

  • The colors - $fish_color_* and $fish_pager_color_*
  • $fish_key_bindings
  • $__fish_initialized

$__fish_initialized is used to guard

  • Setting the colors (as an optimization)
  • Upgrading the abbrs from fish 2.3.0

The optimization, on my system, is worth a whopping 0.25 milliseconds, to be paid on each startup of an interactive shell, and in turn updating the defaults becomes harder as we can't tell a user's customization from our old value anymore.

I am not sure updating the abbrs still works (it's two upgrade steps! Once to 2.3.0 and once to 3.0), and I don't have a system to test. I would actually assume most people use abbr calls in config.fish anyway, and even if they don't calling abbr again isn't too odious.

If these two are gone, $__fish_initialized can just go away entirely.

$fish_key_bindings is possibly more acceptable as a universal variable, given that it is a user choice that is quite unlikely to change between shell instances, but given that this is the last default universal variable I believe that behavior to be too surprising, especially since it necessitates actively switching back if the user decides they don't like vi-bindings.

Going further, it would also be possible to always default to global variables even e.g. for fish_add_path and abbr.

(Personally, I'd be open to removing uvars entirely, but I suspect that's not a popular position)

Activity

  1. added this to the fish 3.2.0 milestone on Sep 7, 2020
  2. IlanCosman commented on Sep 7, 2020

    @IlanCosman
    Contributor

    Removing uvars entirely is an interesting idea. That would fundamentally push fish away from the generally CLI-based configuration it has to a more traditional file-based one. There are quite a few advantages to doing it the file-based way. For example, new users often struggle with the fish paradigm when coming from a traditional shell like bash or zsh. It would also be easier to share configs like people do their .zshrc etc. I'm personally open to the idea, but it would represent a monumental shift for fish.

  3. zanchey commented on Sep 26, 2020

    @zanchey
    Member

    I'm not clear what the benefit is, though?

    Dropping the colour optimisation seems fine as a first action.

  4. faho commented on Sep 26, 2020

    @faho
    MemberAuthor

    I'm not clear what the benefit is, though?

    The benefit of removing default uvars?

    • Less stuff the user doesn't know or care about in the uvar file
    • Easier updating of color defaults - if they're uvars, you only ever get the defaults the first time. If they're global, when we change the defaults they apply on next start (but since we would only set the variable if it isn't set, all you need to do to opt out is to set the variable explicitly)
    • Once we stop setting uvars by default it becomes possible to just ignore uvars entirely

    The case for removing uvars entirely is essentially that I don't feel they're worth the complexity - a lot of questions we get would be easier to answer if uvars didn't exist, and in turn they don't help a lot

  5. krobelus commented on Sep 26, 2020

    @krobelus
    Contributor

    What would happen to fish_config - which currently sets uvars?
    Probably we'd have to change it use set instead of set -U to prevent shadowing.
    The instant color change in all shells would be lost either way, which is something other shells can't do.

    I guess we could make the colors special variables, with default values defined in C++, then we can update the defaults, too.
    Though that's probably too much magic.

    uvars appear convenient, but I agree they add a lot of complexity and potential for confusion.

  6. mattgreen commented on Sep 29, 2020

    @mattgreen

    IMO, dropping uvars is a good idea.

    The instant color change in all shells would be lost either way, which is something other shells can't do.

    Yeah, but if this is the only use we can think of, I don't think they justify a feature which could be emulated with a web-based preview feature on the fish_config page.

    Since it's a user-facing breaking change, waiting until 4.0 to completely axe uvars seems prudent.

  7. ridiculousfish commented on Sep 30, 2020

    @ridiculousfish
    Member

    IMO, good qualities of uvars are instant propagation and persistence. I hope we can keep those features. Bad qualities are:

    1. Don't play nice with dotfiles. Users put set -U... into dotfiles, which is a reasonable mistake, because that's how one configures a shell. And you can't easily put your uvar file in source control either.

    2. Variable scope confusion. It's not always clear when you're setting a uvar vs a global. Shadowing is confusing and the interaction between imported env vars and uvars is particularly ugly.

    3. uvar changes may occur at ambiguous times, along with any --on-variable events; this is annoying to implement, and to test.

    My skeleton proposal is to replace uvars with a new command varsave, like funcsave. This saves a variable into an expressly human-editable file or file section (may or may not be config.fish) by writing fish code into it: set -g varname varvalue...

    Other instances would re-evaluate that file or section when it changes, but only in interactive shells waiting at their prompts. fish itself would never call varsave except as part of fish_config.

    This would eliminate the universal variable scope: it would just be globals getting set in a dotfile, very familiar. I think that gets rid of all of the bad parts of uvars, while keeping the fish magic.

  8. faho commented on Sep 30, 2020

    @faho
    MemberAuthor

    Bad qualities are:

    I agree with your diagnosis.

    My skeleton proposal is to replace uvars with a new command varsave, like funcsave

    Having an explicit synchronization point is a brilliant idea and already makes config.fish work nicer.

    So the replacement for set -U foo bar is set -g foo bar; varsave foo?

    Also this obviously implies varrm, so I'm not sure it shouldn't be set --sync varname... (no values allowed so people don't try set --sync foo bar in config.fish).

    However, this would make it hard to make variables sync from config.fish - how do you create a synced variable? Maybe have set --sync sync if it doesn't exist and set --sync-now sync changes?

    This saves a variable into an expressly human-editable file or file section (may or may not be config.fish) by writing fish code into it: set -g varname varvalue...

    The obvious tricky bit there is updating the statement, also I don't think we've ever altered the user's config.fish. I'd stick with the explicit file, and I'd also pick a different format, to make it clear it's not full code, to keep it machine-editable.


    So, what we should do here is to:

    1. Remove the current default universal variables (probably in 3.3, depending on how soon we're going to release 3.2 - there's some tricky upgrade-related questions)
    2. Open a new issue to discuss a replacement/evolution for uvars.
  9. LastContinue commented on Oct 3, 2020

    @LastContinue

    I don't have too much to add, but since C's are being R'ed

    2. Variable scope confusion... 
    

    Yes. As a new-ish user, seeing -g, -gx -U all do similar but nuanced things makes things "a bit too much fun" sometimes.

    My skeleton proposal is to replace uvars with a new command varsave, like funcsave. This saves a variable into an expressly human-editable file or file section (may or may not be config.fish) by writing fish code into it: set -g varname varvalue...

    I think varsave is pretty reasonable. It preserves I don't want to mess with editing a file for this, and I don't really care if I forget about it flexibility I've come to enjoy with Fish.

    Also, I'd rather not see the variables written in config.fish. I like the separation between "what I do" and "what the system does" in Fish. Having a file filled up with a bunch of stuff I need to navigate around just so I can add a few lines at the bottom would subtract "magic" for sure.

    Additionally anytime you have something automatically adding content to a file that a user can also edit, you can get into a possible clunky stuff like

    #####
    DO/DO NOT EDIT THIS BLOCK
    #####
    

    in the middle of a file with user created content before/after it. Sure it still works, but lacks "style points" 😉

  10. modified the milestones: fish 3.2.0, fish 3.3.0 on Oct 5, 2020
  11. LastContinue commented on Oct 5, 2020

    @LastContinue

    I'm guessing that a possible removal of Universal would also affect abbreviations as well? Would that also then follow the same scheme?

    abbr -ag foo bar; <command to persist abbrs> foo ?

  12. IlanCosman commented on Oct 5, 2020

    @IlanCosman
    Contributor

    I think we should move this discussion about removing all universal variables to a new issue. This issue is for removing the default ones, and should be closed if and when that happens. I have created a new issue: #7379

  13. 4 remaining items

  14. added a commit that references this issue on Jun 19, 2021
    410bc77
  15. added a commit that references this issue on Nov 8, 2021
    e377909
  16. added 5 commits that reference this issue on Nov 17, 2021
    3291305
    d5a539b
    e6044dd
    b55634f
    dd4e822
  17. modified the milestones: fish-future, fish 4.3 on Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions