zsh-workers
 help / color / mirror / code / Atom feed
* Bug?  multicomp no longer works for paths starting with tilde (~)
@ 1998-08-19 19:08 Bart Schaefer
  1998-08-20  8:12 ` Peter Stephenson
  1998-08-20 17:29 ` Bart Schaefer
  0 siblings, 2 replies; 3+ messages in thread
From: Bart Schaefer @ 1998-08-19 19:08 UTC (permalink / raw)
  To: zsh-workers

The multicomp function seems to assume that
   newtop=${~origtop}
will expand to the user's home directory, but that doesn't happen.  Later,
   reply=(${~reply})
also doesn't expand the home directory, and hence finds no matches.

This seems to apply to both 3.0.5 and 3.1.4.  Am I just misunderstanding
what's supposed to be happening?  I reverted back to the baseline 3.1.4
version of multicomp, and it still won't complete anything starting with
a tilde.

The following seems to work better, but messes up if there are wildcards
following the tilde.  Suggestions?

Index: multicomp
===================================================================
*** multicomp	1998/08/19 18:00:16	1.2
--- multicomp	1998/08/19 19:04:22
***************
*** 3,9 ****
  # e.g. s/z/s -> src/zsh-2.4/src
  #
  # Usage: e.g.
! # compctl -D -f + -U -K multicomp
  #
  # Note that exactly matched directories are not expanded, e.g.
  # s/zsh-2.4/s<TAB> will not expand to src/zsh-2.4old/src.
--- 3,9 ----
  # e.g. s/z/s -> src/zsh-2.4/src
  #
  # Usage: e.g.
! # compctl -D -f + -U -Q -K multicomp
  #
  # Note that exactly matched directories are not expanded, e.g.
  # s/zsh-2.4/s<TAB> will not expand to src/zsh-2.4old/src.
***************
*** 32,38 ****
  if [[ "$pref" = \~* ]]; then
    # If the string started with ~, save the head and what it will become.
    origtop="${pref%%/*}"
!   newtop=${~origtop}
    # Save the expansion as the bit matched already
    sofar=($newtop)
    pref="${pref#$origtop}"
--- 32,38 ----
  if [[ "$pref" = \~* ]]; then
    # If the string started with ~, save the head and what it will become.
    origtop="${pref%%/*}"
!   eval newtop=${~origtop}
    # Save the expansion as the bit matched already
    sofar=($newtop)
    pref="${pref#$origtop}"

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Bug? multicomp no longer works for paths starting with tilde (~)
  1998-08-19 19:08 Bug? multicomp no longer works for paths starting with tilde (~) Bart Schaefer
@ 1998-08-20  8:12 ` Peter Stephenson
  1998-08-20 17:29 ` Bart Schaefer
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 1998-08-20  8:12 UTC (permalink / raw)
  To: Zsh hackers list

"Bart Schaefer" wrote:
> The multicomp function seems to assume that
>    newtop=${~origtop}
> will expand to the user's home directory, but that doesn't happen.  Later,
>    reply=(${~reply})
> also doesn't expand the home directory, and hence finds no matches.
> 
> This seems to apply to both 3.0.5 and 3.1.4.  Am I just misunderstanding
> what's supposed to be happening?

No, I think it just hasn't been checked in a long time.

-- 
Peter Stephenson <pws@ifh.de>       Tel: +39 50 844536
WWW:  http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Bug?  multicomp no longer works for paths starting with tilde (~)
  1998-08-19 19:08 Bug? multicomp no longer works for paths starting with tilde (~) Bart Schaefer
  1998-08-20  8:12 ` Peter Stephenson
@ 1998-08-20 17:29 ` Bart Schaefer
  1 sibling, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 1998-08-20 17:29 UTC (permalink / raw)
  To: zsh-workers

On Aug 19, 12:08pm, Bart Schaefer wrote:
} Subject: Bug?  multicomp no longer works for paths starting with tilde (~)
}
} This seems to apply to both 3.0.5 and 3.1.4.  Am I just misunderstanding
} what's supposed to be happening?  I reverted back to the baseline 3.1.4

I've just diffed the 3.0.5 multicomp against a much older one, and found
that the original function used

	eval "reply=($reply)"

where the current version uses

	reply=(${~reply})

The former expands tildes, the latter does not.  However, other changes
make that eval unsuitable for the newer multicomp.

So here's the latest that I have.  The patch below should be applied to
the original 3.1.4 multicomp, that is, -before- (and instead of) my two
previous patches.

I'm still not entirely happy about the handling of metacharacters.  If
the compctl doesn't include -Q, leading tildes get quoted; if it does
include -Q, then other metacharacters do not get quoted.  I think using
a leading tilde is somewhat more common than having file names with an
embedded metacharacter, so I've put -Q in the usage examples.

I suppose a block of $reply:gs/// expressions could be added to quote all
the metacharacters (except tilde), but I'm hoping someone has a better
suggestion.

The test of -z "$head" in the fourth hunk is to prevent having a trailing
"*" appended to completions that end with a "/".  E.g. before,

zsh% ls /u/l/<TAB>

would generate $reply from /usr/local/*, which doesn't seem right.  The
addition of -S '' to the usage examples is to prevent a space from being
inserted following such a trailing slash.  There may be a better approach
to this as well (such as deleting a trailing slash earlier on).

Index: Functions/multicomp
===================================================================
--- multicomp	1998/06/01 17:08:43	1.1
+++ multicomp	1998/08/20 05:59:02
@@ -3,7 +3,7 @@
 # e.g. s/z/s -> src/zsh-2.4/src
 #
 # Usage: e.g.
-# compctl -D -f + -U -K multicomp
+# compctl -D -f + -U -Q -S '' -K multicomp
 #
 # Note that exactly matched directories are not expanded, e.g.
 # s/zsh-2.4/s<TAB> will not expand to src/zsh-2.4old/src.
@@ -22,7 +22,7 @@
 pref="${1}$2"
 # Hack to allow programmable completion to select multicomp after a :
 # (e.g.
-# compctl -D -f -x 's[:]' -U -K multicomp
+# compctl -D -f -x 's[:]' -U -Q -S '' -K multicomp
 # )
 pref="${pref#:}"
 
@@ -32,7 +32,7 @@
 if [[ "$pref" = \~* ]]; then
   # If the string started with ~, save the head and what it will become.
   origtop="${pref%%/*}"
-  newtop=${~origtop}
+  eval "newtop=$origtop"
   # Save the expansion as the bit matched already
   sofar=($newtop)
   pref="${pref#$origtop}"
@@ -48,12 +48,23 @@
   else
     [[ -z "$pref" ]] && globdir=
     # if path segment contains wildcards, don't add another.
-    if [[ "$head" = *[\*\?]* ]]; then
-      wild=
+    if [[ "$head" = *[\[\(\*\?\$\~]* || -z "$head" ]]; then
+      wild=$head
     else
-      wild='*'
+      # Simulate case-insensitive globbing for ASCII characters
+      wild="[${(j(][))${(s())head:l}}]*"	# :gs/a/[a]/ etc.
+      # The following could all be one expansion, but for readability:
+      wild=$wild:gs/a/aA/:gs/b/bB/:gs/c/cC/:gs/d/dD/:gs/e/eE/:gs/f/fF/
+      wild=$wild:gs/g/gG/:gs/h/hH/:gs/i/iI/:gs/j/jJ/:gs/k/kK/:gs/l/lL/
+      wild=$wild:gs/m/mM/:gs/n/nN/:gs/o/oO/:gs/p/pP/:gs/q/qQ/:gs/r/rR/
+      wild=$wild:gs/s/sS/:gs/t/tT/:gs/u/uU/:gs/v/vV/:gs/w/wW/:gs/x/xX/
+      wild=$wild:gs/y/yY/:gs/z/zZ/:gs/-/_/:gs/_/-_/:gs/[]//
+
+      # Expand on both sides of '.' (except when leading) as for '/'
+      wild="${${wild:gs/[.]/*.*/}#\*}"
     fi
-    reply=(${sofar}"${head}${wild}${globdir}")
+
+    reply=(${sofar}"${wild}${globdir}")
     reply=(${~reply})
   fi

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1998-08-20 17:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-08-19 19:08 Bug? multicomp no longer works for paths starting with tilde (~) Bart Schaefer
1998-08-20  8:12 ` Peter Stephenson
1998-08-20 17:29 ` Bart Schaefer

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).