about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>2000-01-21 16:31:07 +0000
committerTanaka Akira <akr@users.sourceforge.net>2000-01-21 16:31:07 +0000
commit2697c3d52cda2cf4f88ab81cde2a37afc1796c7e (patch)
tree960cf063f8ed7205abe169f3cc8648d3a822f750
parent7c109429799172a7bd606593ecf58b8d49b5790f (diff)
downloadzsh-2697c3d52cda2cf4f88ab81cde2a37afc1796c7e.tar.gz
zsh-2697c3d52cda2cf4f88ab81cde2a37afc1796c7e.tar.xz
zsh-2697c3d52cda2cf4f88ab81cde2a37afc1796c7e.zip
zsh-workers/9402
-rw-r--r--Completion/Builtins/_zstyle6
-rw-r--r--Completion/Core/_path_files27
-rw-r--r--Doc/Zsh/compsys.yo23
3 files changed, 54 insertions, 2 deletions
diff --git a/Completion/Builtins/_zstyle b/Completion/Builtins/_zstyle
index 2e95545c2..c239c2c15 100644
--- a/Completion/Builtins/_zstyle
+++ b/Completion/Builtins/_zstyle
@@ -28,6 +28,7 @@ styles=(
   hosts			 c:_hosts
   hosts-ports		 c:host-port
   hosts-ports-users	 c:host-port-user
+  ignore-parents         c:ignorepar
   ignored-patterns	 c:
   insert-unambiguous	 c:bool
   last-prompt		 c:bool
@@ -167,6 +168,11 @@ while [[ -n $state ]]; do
       fi
       ;;
 
+    ignorepar)
+      _wanted values expl 'which parents to ignore' &&
+        compadd "$expl[@]" parent pwd .. directory
+      ;;
+
     _*)
       ${=ostate}
       ;;
diff --git a/Completion/Core/_path_files b/Completion/Core/_path_files
index 9c1be30bf..8c3b4ca63 100644
--- a/Completion/Core/_path_files
+++ b/Completion/Core/_path_files
@@ -5,7 +5,7 @@
 
 local linepath realpath donepath prepath testpath exppath
 local tmp1 tmp2 tmp3 tmp4 i orig eorig pre suf tpre tsuf opre osuf cpre
-local pats haspats=no ignore group expl addpfx addsfx remsfx
+local pats haspats=no ignore group expl addpfx addsfx remsfx rem remt
 local nm=$compstate[nmatches] menu mspec matcher mopts atmp sort match
 
 typeset -U prepaths exppaths
@@ -300,8 +300,31 @@ for prepath in "$prepaths[@]"; do
       tmp2=( ${^tmp1}${^~pats} )
       [[ ! -o globdots && "$PREFIX" = .* ]] &&
           tmp2=( "$tmp2[@]" ${^tmp1}.${^~pats} )
+      if (( $#tmp2 )) &&
+         zstyle -s ":completion${curcontext}:files" ignore-parents rem &&
+	 [[ ( "$rem" != *dir* || "$pats" = '*(-/)' ) &&
+	    ( "$rem" != *..* || "$tmp1" = *../* ) ]]; then
+        if [[ "$rem" = *parent* ]]; then
+	  for i in "$tmp2[@]"; do
+	    if [[ -d "$i" && "$i" = */* ]]; then
+	      remt="${i/*}"
+	      while [[ "$remt" = */* ]]; do
+		[[ "$remt" -ef "$i" ]] && break
+		remt="${remt%/*}"
+	      done
+	      [[ "$remt" = */* || "$remt" -ef "$i" ]] &&
+	          _comp_ignore=( "$_comp_ignore[@]" "${(q)i}" )
+	    fi
+	  done
+        fi
+        if [[ "$rem" = *pwd* ]]; then
+          for i in "$tmp2[@]"; do
+	    [[ "$i" -ef "$PWD" ]] && _comp_ignore=( "$_comp_ignore[@]" "${(q)i}" )
+	  done
+        fi
+      fi
       if [[ "$sopt" = *[/f]* && ( -o globdots || "$PREFIX" = .* ) ]] &&
-	 zstyle -s ":completion${curcontext}:paths" special-dirs atmp; then
+	  zstyle -s ":completion${curcontext}:paths" special-dirs atmp; then
 	if [[ "$atmp" = (yes|true|1|on) ]]; then
 	  tmp2=( "$tmp2[@]" . .. )
 	elif [[ "$atmp" = .. ]]; then
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 384f9db29..f25ef093f 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -876,6 +876,29 @@ item(tt(hosts-ports-users))(
 Like tt(hosts-ports) but used for commands like tt(telnet) and
 containing strings of the form `var(host)tt(:)var(port)tt(:)var(user)'.
 )
+item(tt(ignore-parents))(
+When completing files it is possible to make names of directories
+already mentioned on the line or the current working directory be
+ignored. The style is tested for the tt(files) tag and if its value
+contains the string tt(parent), then the name of any directory whose
+path is already contained in the word on the line is ignored. For
+example, when completing after tt(foo/../), the directory tt(foo) will
+not be considered a valid completion.
+
+If the style contains the string tt(pwd), then the name of the current 
+working directory will not be completed, so that, for example,
+completion after tt(../) will not use the name of the current
+directory.
+
+If the style contains the string tt(..) both tests will only be
+performed if the word on the line contains the substring tt(../) and
+if the value contains the string tt(directory), then the tests will
+only be performed if only names of directories are completed.
+
+Note that names of directories ignored because of one of the tests
+will be placed in the alternate set of completions so that they will
+be completed if there are no other possible completions.
+)
 item(tt(ignored-patterns))(
 This style is used with the tags used when adding matches and gives a
 number of patterns. All matches that are matched by any of these