Repository navigation
implement "tied" variables - #4082
krader1961 wants to merge 3 commits into
Conversation
|
Not too surprisingly it turns out that doing this entirely in fish script has one slightly annoying drawback. When setting one of the tied variables local to a block (i.e., Note that zsh has a similar limitation but its inverse: In zsh creating a local version of one of the tied vars does not affect its mirror in that block. On the other hand when you exit the block both are back in sync. I haven't done more testing but I think the behavior this change introduces is somewhat more obvious. |
|
Also, regarding |
|
Tied variables seem like an Extremely Magic feature! Is there some way we can warn people if they're setting a tied variable? |
I'm okay with making this a behavior of the
Sure, but such messages tend to be annoying. We'd obviously want to limit how often they're issued. Just once the first time a user changes any tied variable? Just once when they attempt to change one of the six auto-created tied variables? Or once for each tied variable? We could also document a global or universal var the user could set to inhibit those messages. |
|
FYI, I decided that requiring the user to deal with |
People have wanted a way to more transparently handle other env vars that are implicitly lists much like fish already does for PATH, MANPATH, and CDPATH. I was originally leaning towards augmenting the set builtin to allow the user to mark other vars for the same magic treatment. But after much thought I decided the zsh "tied" variable feature is more flexible and easier to user. This change implements that for fish. Fixes #436
I was hoping to keep the entire tied var implemention in fish script. Unfortunately there isn't any way to do so -- at least not transparently. This change makes it transparent. Fixes #436
The `man` function happened to define a variable named `fish_manpath` which conflicts with the newly introduced tied array var by that name.
|
At this point in time I'm primarily interested in whether anyone has an objection to introducing a I'm going to let this soak for a couple more days and if no one has objections merge it. |
|
I'd stick with |
|
Okay, a couple of people have expressed a desire to use Does anyone have an opinion on making |
|
No one else has an opinion? If no one else says anything in the next couple of days I'm going to close this PR and reimplement this feature in terms of |
Honestly, I still don't quite get the feature. I can see how it'd be cleaner for $PATH et al since those aren't special-cased anymore, but I don't think I'd ever use it. I'd rather I do have a slight preference for |
|
@faho: This means that all the other path like env vars people work with (e.g., |
|
Seems like an interesting feature. I like that you can specify the separator. I'm not a fan of the tied var implicitly changing which variable it is tied to based on the scope it's accessed from (I like Zsh's behaviour). |
I don't understand. It doesn't change which var it is tied to. However, if you localize one of them it does automatically localize the other. That is what most people will expect. When I saw how zsh handled localizing a tied variable I was quite surprised at the result. |
set -l gopath /path3 /path4From here, I assumed that this created a new variable within the block's scope. Like JavaScript's |
|
@JoshCheek: That's how the implementation works. If you run the following script with a fish built with this PR you'll see this output: If you're expecting something else I'm confused what behavior you're expecting. Here is the script: |
|
Do you think this behavior may conflict with scripts that assume that variables can be changed independently? (Imagine a script that naively backs up/restores all the global variables that cannot restore the original variable values after two variables are tied together.) |
|
@szhu: Yes, this is definitely not a zero risk change. Same is true for the change in behavior of |
|
Why was this closed? Tied variables would be cool for 3.0. |
|
Nevermind, I see the |
People have wanted a way to more transparently handle other env vars
that are implicitly lists much like fish already does for PATH, MANPATH,
and CDPATH. I was originally leaning towards augmenting the set builtin
to allow the user to mark other vars for the same magic treatment. But
after much thought I decided the zsh "tied" variable feature is more
flexible and easier to use. This change implements that for fish.
Fixes #436
TODOs:
The documentation needs more work. I also need to add more unit tests to verify corner cases. But the core implementation seems solid so I wanted to get this out for discussion.
I am ambivalent about whether to introduce a new
tiecommand or augmentsetwith-T/--tieand-U/--untieflags. Thoughts?