zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: Zsh Workers <zsh-workers@sunsite.dk>
Subject: Re: "keep-prefix true" feature request
Date: Fri, 13 Apr 2001 04:50:04 +0000	[thread overview]
Message-ID: <1010413045004.ZM1107@candle.brasslantern.com> (raw)
In-Reply-To: <Pine.LNX.4.30.0104121912010.7928-100000@phong.blorf.net>

On Apr 12,  7:30pm, Wayne Davison wrote:
} Subject: "keep-prefix true" feature request
}
}   % cd ~xpkg/apache$htd/<TAB>
}
} Now it's just beeping at me unless I change the '~' into a '$'.  

This comes from the test at line 193 of _path_files.  If there's a
leading tilde, it expands the tilde-expression but never expands the
stuff to the right of the first slash.  If there's no leading tilde,
the branch at line 244 is taken and everything gets expanded.

(This is also why your "automatic hash -d" doesn't work:  it expands
the tilde-expression by checking whether there is already a dirstack
entry, not by actually evaluating the expression.)

It *seems* to work just to swap those two branches (test for $ first,
then leading tilde), and in fact that *also* seems to handle this:

} I'd like the "keep-prefix true" setting to work a little differently.
} It keeps a variable from expanding only if it is the first item in the
} filename, and I'd like it to avoid expanding any variable that has
} text after it (like the old completion system does).

I'm sure somebody can explain to me why the following is wrong.

Index: Completion/Unix/Type/_path_files
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_path_files,v
retrieving revision 1.1
diff -u -r1.1 _path_files
--- Completion/Unix/Type/_path_files	2001/04/02 11:36:27	1.1
+++ Completion/Unix/Type/_path_files	2001/04/13 04:44:16
@@ -190,7 +190,23 @@
 
 # Now let's have a closer look at the string to complete.
 
-if [[ "$pre[1]" = \~ && -z "$compstate[quote]" ]]; then
+if [[ "$pre" = *\$*/* && "$compstate[quote]" != \" ]]; then
+
+  # If there is a parameter expansion in the word from the line, we try
+  # to complete the beast by expanding the prefix and completing anything
+  # after the first slash after the parameter expansion.
+  # This fails for things like `f/$foo/b/<TAB>' where the first `f' is
+  # meant as a partial path.
+
+  linepath="${(M)pre##*\$[^/]##/}"
+  eval 'realpath=${(e)~linepath}' 2>/dev/null
+  [[ -z "$realpath" || "$realpath" = "$linepath" ]] && return 1
+  pre="${pre#${linepath}}"
+  i="${#linepath//[^\\/]}"
+  orig="${orig[1,(in:i:)/][1,-2]}"
+  donepath=
+  prepaths=( '' )
+elif [[ "$pre[1]" = \~ && -z "$compstate[quote]" ]]; then
   # It begins with `~', so remember anything before the first slash to be able
   # to report it to the completion code. Also get an expanded version of it
   # (in `realpath'), so that we can generate the matches. Then remove that
@@ -239,22 +255,6 @@
   [[ "$realpath" = "$linepath" ]] && return 1
   pre="${pre#*/}"
   orig="${orig#*/}"
-  donepath=
-  prepaths=( '' )
-elif [[ "$pre" = *\$*/* && "$compstate[quote]" != \" ]]; then
-
-  # If there is a parameter expansion in the word from the line, we try
-  # to complete the beast by expanding the prefix and completing anything
-  # after the first slash after the parameter expansion.
-  # This fails for things like `f/$foo/b/<TAB>' where the first `f' is
-  # meant as a partial path.
-
-  linepath="${(M)pre##*\$[^/]##/}"
-  eval 'realpath=${(e)~linepath}' 2>/dev/null
-  [[ -z "$realpath" || "$realpath" = "$linepath" ]] && return 1
-  pre="${pre#${linepath}}"
-  i="${#linepath//[^\\/]}"
-  orig="${orig[1,(in:i:)/][1,-2]}"
   donepath=
   prepaths=( '' )
 else

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


  reply	other threads:[~2001-04-13  4:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-13  2:08 Automatic hash -d Wayne Davison
2001-04-13  2:30 ` "keep-prefix true" feature request Wayne Davison
2001-04-13  4:50   ` Bart Schaefer [this message]
2001-04-13  5:09     ` Automatic hash -d Bart Schaefer
2001-04-13  8:01       ` Wayne Davison
2001-04-13 15:38         ` Bart Schaefer
2001-04-13 16:47       ` Bart Schaefer
2001-04-17  9:04         ` Sven Wischnowsky
2001-04-18  5:56           ` PATCH (?): " Bart Schaefer
2001-04-18  8:29             ` Sven Wischnowsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1010413045004.ZM1107@candle.brasslantern.com \
    --to=schaefer@candle.brasslantern.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).