Repository navigation
Introduce path variables - #5245
ridiculousfish wants to merge 3 commits into
Conversation
This commit begins to bake in a notion of path-style variables.
Prior to this fix, fish would export arrays as ASCII record separator
delimited, except for a whitelist (PATH, CDPATH, MANPATH). This is
surprising and awkward for other programs to deal with, and there's no way
to get similar behavior for other variables like GOPATH or LD_LIBRARY_PATH.
This commit does the following:
1. Exports all arrays as colon delimited strings, instead of RS.
2. Introduces a notion of "path variable." A path variable will be
"colon-delimited" which means it gets colon-separated in quoted expansion,
and automatically splits on colons. In this commit we only do the exporting
part.
Colons are not escaped in exporting; this is deliberate to support uses
like
`set -x PYTHONPATH "/foo:/bar"`
which ought to work (and already do, we don't want to make a compat break
here).
This switches quoted expansion like "$foo" to use foo's delimiter instead of space. The delimiter is space for normal variables and colonf or path variables. Expansions like "$PATH" will now expand using ':'.
This adds flags --path and --unpath to builtin set, analogous to --export and --unexport. These flags change whether a variable is marked as a path variable. Universal variables cannot yet be path variables.
|
How does this work across sessions? For example, if I have |
|
If you want to set a variable to a fixed value without inferring its path status, you can do it: To "recongeal" a path variable to a single string with colons: This is a little sneaky:
|
I'm not entirely sure what that means. Do you mean it needs to be specified every time, otherwise we fall back to the default? I.e. set --path foo bar:baz # results in two elements
set foo bingo:bongo # results in one element because it reverts to not a path
set --unpath FOOPATH bingo:bongo # one element
set FOOPATH bar:baz # two elements because it reverts to a pathThat seems like it would make non-default variables a tad annoying. What's the rationale here? |
Space is the most generally useful. I suppose that means we've given up on inheriting lists?
Doesn't seem all that useful, no. |
No, if you don't specify More precisely, the behavior is:
This matches the behavior of |
That'll work! |
This merges support for PATH variables. Closes fish-shell#5245
Since version 3.0, fish treats all variables with names ending in PATH as colon-separated, and splits them automatically on assignment. See fish-shell/fish-shell#5245
This PR is another go at #436, more ambitious than #5188.
This introduces a notion of "path variables." Path variables provide special support for colon-delimited variables including PATH, PYTHONPATH, GOPATH, etc.
Path variables act as normal variables except:
:instead of space inside quotes.echo "$PATH"will have colons.set PATH "/tmp/bin:$PATH"will no longer result in a bogus PATH. Path variables cannot contain colons themselves.Variables that end in "PATH" are automatically path variables. Variables can be queried for their path status (though somewhat awkwardly) via
set -q.Users can mark a variable as path via
set --path MYVAR SOMEVALUE, orset --unpathto mark it as not a path. This property is tied to a variable (not its name) similar to--exportand--unexport.I played around with a notion of having each variable track a settable delimiter but found it to be too complex; I think having specific support for path-style variable is just right and not overly constraining for the future.
Unanswered questions: