Honor dirprev scope (#5796)

* Honour `dirprev` scope

Honour the scope of the `dirprev` variable if it is universal
and avoid to shadow it with a global. This enables to share
the `cd` history between sessions.

* Honor dirnext and __fish_cd_direction scope

If these variables exist in the universal scope, do not shadow them
This commit is contained in:
Geographer 2019-04-12 09:43:34 +02:00 committed by Fabian Homborg
parent 898ed12a6c
commit 9cf1b18b26

View File

@ -41,9 +41,21 @@ function cd --description "Change directory"
or set -l dirprev
set -q dirprev[$MAX_DIR_HIST]
and set -e dirprev[1]
set -g -a dirprev $previous
set -e dirnext
set -g __fish_cd_direction prev
# If dirprev, dirnext, __fish_cd_direction
# are set as universal variables, honour their scope.
set -U -q dirprev
and set -U -a dirprev $previous
or set -g -a dirprev $previous
set -U -q dirnext
and set -U -e dirnext
or set -e dirnext
set -U -q __fish_cd_direction
and set -U __fish_cd_direction prev
or set -g __fish_cd_direction prev
end
return $cd_status