Export arrays as colon delimited, and support path-style variables

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 commit is contained in:
ridiculousfish
2018-09-09 18:32:15 -07:00
parent ff042bbb7b
commit 3f3b3a7006
9 changed files with 104 additions and 61 deletions

View File

@@ -848,7 +848,18 @@ A range of indices can be specified, see <a href='#expand-index-range'>index ran
All arrays are one-dimensional and cannot contain other arrays, although it is possible to fake nested arrays using the dereferencing rules of <a href="#expand-variable">variable expansion</a>.
`fish` automatically creates arrays from the variables `PATH`, `CDPATH` and `MANPATH` when it is started. (Previous versions created arrays from *all* colon-delimited environment variables.)
When an array is exported as an environment variable, it is either space or colon delimited, depending on whether it is a path variable:
\fish
set -x smurf blue small
set -x smurf_PATH forest mushroom
env | grep smurf
<outp>
# smurf=blue small
# smurf_PATH=forest:mushroom
</outp>
\endfish
`fish` automatically creates arrays from all environment variables whose name ends in PATH, by splitting them on colons. Other variables are not automatically split.
\subsection variables-special Special variables