diff --git a/.config/fish/conf.d/smartcd.fish b/.config/fish/conf.d/smartcd.fish index 3121c42d..ff2640ea 100644 --- a/.config/fish/conf.d/smartcd.fish +++ b/.config/fish/conf.d/smartcd.fish @@ -1,12 +1,10 @@ status is-interactive; or exit -# necessary because we want to use fish's -# cd wrapper function, _not_ the builtin cd! -if not functions -q __cd_orig - functions --copy cd __cd_orig -end +# Ensure original cd is saved once +functions -q __cd_orig; or functions --copy cd __cd_orig function cd --wraps=cd --description "Change directory. No args goes to git root or $HOME. If already there, return to previous location." + # Skip history in subshells. if status --is-command-substitution builtin cd $argv @@ -25,24 +23,20 @@ function cd --wraps=cd --description "Change directory. No args goes to git root if not test (pwd) = $root __cd_orig $root else if set -q dirprev - echo "prev: $dirprev[-1] - root: $root" - set -x smartdirprev $dirprev[-1] - set -x smartroot $root if string match -q "$root*" "$dirprev[-1]" - echo We out here __cd_orig - else - set -l prompt "This would take you to $dirprev[-1], which is outside $root, are you sure? (y/n): " + set -l prompt "$dirprev[-1], is outside $root, are you sure? (y/n): " while read --nchars 1 -l response --prompt-str="$prompt" or return 1 + # clear prompt + printf "\033[1A\033[2K" + # printf "\033[1A\033[2K" switch $response case y Y __cd_orig - break case n N break - case '*' - continue end end end