-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix fish_config theme save
#9273
Conversation
share/functions/fish_config.fish
Outdated
# If we are persisting a theme, either get its name from $argv[1] or | ||
# from the last chosen theme. | ||
if contains -- $cmd choose | ||
set -g __fish_last_chosen_theme $argv[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't the right way to go about this.
The current theme is just the set of the current color variables, so running fish_config theme save
should just persist the current variables (to universal variables)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically, what you need to do is just not read any file if $argv is empty, and instead only do the saving part.
So an if set -q argv[1]
on line 226 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In essence, fish_config theme save
or fish_config prompt save
is the "I'm happy with this" button. It just saves the current config.
So if you do fish_config theme choose coolbeans
, and you decide that it's nice, and then you do fish_config theme save
it should save the coolbeans theme, but if you decide to change a color or two and then fish_config theme save
it should save the theme with those alterations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, thanks.
I pushed an update that addresses your concerns, @faho. (I didn't force push, but I'll squash the commits into the latter if we end up going with that direction). Note that the latest commit includes an important caveat/note:
I think we have to search for all variables that match the whitelist filter we use when loading a theme from disk and persist all of those, not just the known colors? Basically, replace |
7a144aa
to
d66c19f
Compare
|
Actually, thanks for reminding me to use I just pushed an update that does that; I think now we can comfortably use Separate from this pull request, I think it might be more correct for loading ("choosing") a theme to unset any pattern-matched variables that weren't overwritten in the new theme; e.g. theme A sets '$fish_color_custom' then theme B is loaded - I think loading theme B should maybe erase But I'm not sure if there are prompts that set any custom colors; we wouldn't want |
2a3617f
to
590117c
Compare
The documentation states that running `fish_config theme save` after `fish_config theme choose [theme_name]` will result in "saving" the currently chosen theme, but this does not match the actual behavior of `fish_config theme save` which expects a trailing argument specifying the name of the theme to select/persist. Given that the documented way has been included in a release and that it makes more sense than calling `fish_config theme save xxx` when you are *loading from* xxx and not *saving to* xxx, this patch revises `fish_config.fish` to support the documented behavior. When `fish_config theme save xxx` is used, xxx is loaded w/ its specified colors saved to the according variables in the universal scope. But if `fish_config theme save` is used without a theme's name specified, then the currently specified (known) fish color variables are persisted from whatever scope they're currently in (usually in the global scope from previewing a theme) to universal variables of the same name. This does *not* catch color variables unknown to fish! If a theme and a prompt agree on some variable to hold some color but it's not a color variable known to fish, it won't be persisted! Closes fish-shell#9088.
Don't just save known color values but any values that could have been loaded from a .theme file. Also, refactor the theme variable name whitelist/filter in a shared "global" variable so we never forget to update it at any of the individual use sites.
590117c
to
201a0d7
Compare
The documentation states that running
fish_config theme save
afterfish_config theme choose [theme_name]
will result in "saving" the currently chosen theme, but this does not match the actual behavior offish_config theme save
which expects a trailing argument specifying the name of the theme to select/persist.Given that the documented way has been included in a release and that it makes more sense than calling
fish_config theme save xxx
when you are loading from xxx and not saving to xxx, this patch revisesfish_config.fish
to support the documented behavior.When
fish_config theme choose xxx
is used, xxx is saved to a hidden global variable__fish_last_chosen_theme
. Iffish_config theme save
is called without a theme name specified, then this global variable is searched for the name of the last chosen theme and that is saved/persisted as the default theme.Closes #9088.
I'm requesting a review because I have no idea how
fish_config
is meant to be used and I'm going solely off what I read in the function -- I've never used it myself. I'm just conforming the code to the existing docs.