Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH (?) Re: [zsh 4.0.1 bug] filename completion



Bart Schaefer wrote:

> ...
> 
> } But this isn't a really good solution, because with that and directories
> } `~soft/foo' and `software/foo' completion after `cd soft/f<TAB>' lists
> } the `foo's, not the ambiguous prefix
> 
> Hrm.  That's a pretty minor problem by comparison.  Particularly since it
> will (appear to) do the right thing if there are at least two directories
> starting with `f' that don't share a whole name in common.

Yes.

> } Because of that I'm not going to commit that part of the patch
> 
> I think you should commit it.  Anybody else have an opinion?

Thinking again yesterday evening, I came to the conclusion that's it's
at least better than what we have now and to commit it.


In another mail:

> One complication of this is:
> 
> schaefer<509> cd soft/<TAB>
> Completing directories after cdablevar
> software/       src/            sparc-solaris/  share/          scripts/      
> Completing local directories
> subdir/
> 
> The "local directory" listed above is really ./software/subdir/.  Cycling
> through the menu completions inserts it properly -- it's just the display
> that is wrong.

Yes, that's what I meant.  A result of calling _path_files twice with
different prefixes.

May main problem is probably that I fail to see the `larger problem
behind this' so that I could try to tackle that.  Modifying _path_files
just to improve this one case doesn't look like the right thing.


Bye
  Sven

Index: Completion/Zsh/Command/_cd
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Command/_cd,v
retrieving revision 1.2
diff -u -r1.2 _cd
--- Completion/Zsh/Command/_cd	2001/06/21 09:33:16	1.2
+++ Completion/Zsh/Command/_cd	2001/06/28 07:34:03
@@ -5,7 +5,7 @@
 #    and the string doesn't begin with ~, /, ./ or ../.
 #  - In the second argument to cd for the form `cd old new', completes
 #    possible `new' strings by examining `old' and $PWD.
-#  - After - or +, completes numbers, but the listing
+#  - After - or +, _directory_stack completes numbers, but the listing
 #    gives you the list of directories to complete.  This turns on
 #    menu-completion and lists the possibilities automatically, otherwise
 #    it's not a lot of use.  If you don't type the + or - it will
@@ -24,31 +24,55 @@
   rep=(${${rep#${PWD%%$words[2]*}}%${PWD#*$words[2]}})
   (( $#rep )) && _wanted -C replacement strings expl replacement compadd -a rep
 else
-  [[ CURRENT -gt 1 ]] && _directory_stack && ret=0
-
-  if [[ $PREFIX != (\~|/|./|../)* && $#cdpath -ne 0 ]]; then
-    local tdir tdir2
+  # Complete directory stack entries with ~ or when not in command position
+  # (the rest of this test is optimization for the _tilde call below)
+  if [[ "$PREFIX" == (#b)(\~|)[^/]# &&
+      ( -n "$match[1]" || ( CURRENT -gt 1 && ! -o cdablevars ) ) ]]; then
+    _directory_stack && ret=0
+  fi
 
-    # With cdablevars, we can convert foo/bar/... to ~foo/bar/... if
-    # there is no directory foo.  In that case we could also complete
-    # variable names, but it hardly seems worth it.
-    # Note we need a tilde because cdablevars also allows user home
-    # directories, hence we also need nonomatch to suppress error messages.
-    if [[ -o cdablevars && -n "$PREFIX" && ! -d ${tdir::=${PREFIX%%/*}} &&
-          -d ${~tdir2::="~$tdir"} ]]; then
-      PREFIX="~$PREFIX"
-      _wanted directories expl directory _path_files -/ && ret=0
-    else
-      local tmpcdpath
-
-      tmpcdpath=(${${(@)cdpath:#.}:#$PWD})
-      _alternative \
-          'local-directories:local directories:_path_files -/' \
+  if [[ $PREFIX != (\~|/|./|../)* ]]; then
+    local tmpcdpath
+    tmpcdpath=(${${(@)cdpath:#.}:#$PWD})
+
+    # With cdablevars, we can complete foo as if ~foo/
+    if [[ -o cdablevars && -n "$PREFIX" ]]; then
+      if [[ "$PREFIX" != */* ]]; then
+        _tilde && ret=0
+      else
+        local oipre="$IPREFIX" opre="$PREFIX" dirpre dir
+
+	# Note we need a tilde because cdablevars also allows user home
+	# directories, hence nonomatch (above) to suppress error messages.
+
+        dirpre="${PREFIX%%/*}/"
+        IPREFIX="$IPREFIX$dirpre"
+        eval "dir=( ~$dirpre )"
+        PREFIX="${PREFIX#*/}"
+
+        [[ $#dir -eq 1 && "$dir[1]" != "~$dirpre" ]] &&
+          _wanted named-directories expl 'directories after cdablevar' \
+	      _path_files -W dir -/ && ret=0
+
+        PREFIX="$opre"
+        IPREFIX="$oipre"
+      fi
+    fi
+    if [[ $#tmpcdpath -ne 0 ]]; then
+      # Don't complete local directories in command position, that's
+      # already handled by _command_names (see _autocd)
+      if [[ CURRENT -eq 1 ]]; then
+	_wanted path-directories expl 'directories in cdpath' \
+	  _path_files -W tmpcdpath -/ && ret=0
+      else
+        _alternative \
+	  'local-directories:local directories:_path_files -/' \
 	  "path-directories:directories in cdpath:_path_files -W tmpcdpath -/" && ret=0
+      fi
+      return ret
     fi
-  else
-    _wanted directories expl directory _path_files -/ && ret=0
   fi
+  _wanted directories expl directory _path_files -/ && ret=0
 
   return ret
 fi
Index: Completion/Zsh/Context/_tilde
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Context/_tilde,v
retrieving revision 1.1
diff -u -r1.1 _tilde
--- Completion/Zsh/Context/_tilde	2001/04/02 11:24:49	1.1
+++ Completion/Zsh/Context/_tilde	2001/06/28 07:34:03
@@ -6,7 +6,7 @@
 
 [[ -n "$compstate[quote]" ]] && return 1
 
-local expl suf dirs list lines revlines i ret disp nm="$compstate[nmatches]"
+local expl suf ret
 
 if [[ "$SUFFIX" = */* ]]; then
   ISUFFIX="/${SUFFIX#*/}$ISUFFIX"

-- 
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author