From 1af38d69a81fcc7d6e1fd7f7ac7b6e42e96951ce Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 13 Oct 2017 18:32:36 +0200 Subject: [PATCH] Fix cd completions if a directory exists in $CDPATH and $PWD E.g. if "foo" is in CDPATH, and both "foo/bar" and "./bar" exist, `cd bar` will go to ./bar. The completions described "bar" as going to "foo/bar" ("CDPATH foo"). This fixes it by checking for ./bar's existence. See #4475. --- share/functions/__fish_complete_cd.fish | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/share/functions/__fish_complete_cd.fish b/share/functions/__fish_complete_cd.fish index 190f9b935..f530120ca 100644 --- a/share/functions/__fish_complete_cd.fish +++ b/share/functions/__fish_complete_cd.fish @@ -30,9 +30,14 @@ function __fish_complete_cd -d "Completions for the cd command" set -l desc (string replace -r -- "^$HOME" "~" "$cdpath") # This assumes the CDPATH component itself is cd-able. for d in $cdpath/$token*/ + set -l withoutcdpath (string replace -- "$cdpath/" "" $d) + # Skip if the path exists in the current directory, since that's what `cd` will use. + if test -d "$withoutcdpath" -a -x "$withoutcdpath" + continue + end # Remove the cdpath component again. test -x $d - and printf "%s\tCDPATH %s\n" (string replace -r "^$cdpath/" "" -- $d) $desc + and printf "%s\tCDPATH %s\n" "$withoutcdpath" $desc end end end