From 9cf1b18b268db9c85bd52f9efb9615fb6d3fe4a7 Mon Sep 17 00:00:00 2001 From: Geographer Date: Fri, 12 Apr 2019 09:43:34 +0200 Subject: [PATCH] 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 --- share/functions/cd.fish | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/share/functions/cd.fish b/share/functions/cd.fish index eed8a9f94..74ef09d41 100644 --- a/share/functions/cd.fish +++ b/share/functions/cd.fish @@ -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