Repository navigation
Export arrays as colon delimited, and splitenv PATH env vars - #5188
ridiculousfish wants to merge 2 commits into
Conversation
|
I'm fine with premise of exporting arrays as colon-delimited strings, but I think that the behavior needs to be consistent with regards to how fish treats them within a session. i.e. I don't like that this currently happens: mqudsi@QBook ~/R/fish-shell> env PYTHONPATH="/foo:/bar" fish
...
mqudsi@QBook ~/R/fish-shell> echo \"$PYTHONPATH\"
"/foo" "/bar"
mqudsi@QBook ~/R/fish-shell> set -x PYTHONPATH "/foo:/bar"
mqudsi@QBook ~/R/fish-shell> echo \"$PYTHONPATH\"
"/foo:/bar"
mqudsi@QBook ~/R/fish-shell> set -x PYTHONPATH /foo /bar
mqudsi@QBook ~/R/fish-shell> echo \"$PYTHONPATH\"
"/foo "/bar"I understand that what I'm seeing here is fish preserving what I typed in as I typed it, but that's only going to cause problems when it comes to appending variables to existing arrays. If fish imports these variables split, then I would expect this to be the output: mqudsi@QBook ~/R/fish-shell> set -x PYTHONPATH "/foo:/bar"
mqudsi@QBook ~/R/fish-shell> echo \"$PYTHONPATH\"
"/foo" "/bar"
mqudsi@QBook ~/R/fish-shell> set -x PYTHONPATH /foo /bar
mqudsi@QBook ~/R/fish-shell> echo \"$PYTHONPATH\"
"/foo" "/bar"basically, the same logic applied to incoming variables is applied within a session, namely any variables that are exported should be split on Especially as you mention you have no intention of allowing for escaping the colon (which I'm fine with), which means there can never literally be an array member |
|
Thanks. It sounds like there's interest from both mqudsi and faho to make the splitting behavior a property of the variable itself. That will require maintaining some more internal state but is certainly not hard. |
bf73abf to
0bf6c2a
Compare
splitenv takes a variable name, and sets that variable to its value but split on colons. Proposed in fish-shell#436
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. When importing environment variables, if the variable ends in PATH, split it on colons (i.e. splitenv); otherwise do not split it. Colons are not escaped; 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). Fixes (or at least mitigates) fish-shell#436
0bf6c2a to
74a6beb
Compare
|
#5245 sounds much nicer to me, and I think we're in agreement on that, so I'm closing this. If anyone disagrees and wants to have this instead, speak up! |
This PR is an attempt to partially solve #436
The big changes here:
splitenvfunction makes it easy to split additional variables on colons;string joincan go the other wayThe advantage of this approach is that it will do the right thing for nearly all colon-delimited variables: PYTHONPATH, GOPATH, MANPATH, PATH, etc, while not mucking with undelimited variables that might contain colons (e.g. DISPLAY). It is also simple to implement, and provides a simple story for anything it gets wrong (
splitenv/string join). It is also compatible with fish 2.x scripts in that PATH and MANPATH are retained as arrays. Overall it is a practical and pragmatic tradeoff, not perfection.Crucially colons are not escaped. This is to support uses like
set MANPATH "/foo:/bar"which ought to just work. Traditionally such paths cannot contain colons and escapes are not honored (e.g. there's no way to add a colon to a PATH segment) so this is not a loss.One compatibility risk is that we will split some paths where previously we did not. For example, code like this:
will now fail if the incoming PYTHONPATH contained a colon. We'll have to see whether this is encountered by anyone; if so we might have to expand such variables differently inside quotes (yuck) or do something else more exotic.
A secondary disadvantage is that exported fish arrays will appear as colon delimited strings on recursive invocations of fish. The hypothesis is that this is a rare scenario and can be handled by
splitenv.Universal variables continue to use record separators internally and aren't affected by this.