zsh-users
 help / color / mirror / code / Atom feed
* completing second argument of cd
@ 1996-07-22  8:36 Peter Stephenson
  1996-07-22 14:59 ` Zoltan Hidvegi
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 1996-07-22  8:36 UTC (permalink / raw)
  To: Zsh users list

I don't remember seeing a function like this posted before... it's for
use with compctl and completes the second argument of cd, i.e. it
tries to find a possible new directory by altering an occurrence of
the existing cd argument in $PWD.

e.g.

% pwd
/home/sgi/pws/lgt/su2/phase/data/12_6/2.4
% cd 12_6 <TAB>      ->      cd 12_6 8_4
~/lgt/su2/phase/data/8_4/2.4

(yes, I wrote this to save typing three characters :-))

The comment about the bug refers to this:
% pwd
/groupfs/schierholz3/stephens/b6p00kp1550.bub/rho
% cd rho pion
cd: no such file or directory:
/groupfs/schiepionlz3/stephens/b6p00kp1550.bub/rho

(I've split the error message):  in other words, there's a perfectly
good directory /groupfs/schierholz3/stephens/b6p00kp1550.bub/pion, but
the shell has decided willy-nilly that the first rho it finds is the
one to change.  It's a philosophical bug, if you consider zsh is
supposed to be smart :-).

Here's the function.


# cdswap:  function to be used for completion of second argument of cd
# or pushd.
# Usage:
#   compctl -g '*(-/)' -x 'p[2]' -K cdswap -- cd pushd
# May be combined with $CDPATH searching functions, e.g.:
#   compctl -g '*(-)' -x 'p[2]' -K cdswap -- + -K cdmatch -S / -q cd pushd
# Peter Stephenson (pws@ifh.de)

# reset options after use:  no reply if no match
setopt localoptions nullglob
# stripped bits of PWD not to be eligible for globbing:
# use zsh-style arrays
unsetopt globsubst ksharrays

local args
# args looks like (cd old new)
read -Ac args

# Always use first match for $args[2] (this is how cd works regardless
# of whether resulting directory exists --- is this a bug?)
reply=(${PWD%%$args[2]*}*${PWD#*$args[2]}~$PWD)
reply=(${${reply#${PWD%%$args[2]*}}%${PWD#*$args[2]}})


-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.


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

* Re: completing second argument of cd
  1996-07-22  8:36 completing second argument of cd Peter Stephenson
@ 1996-07-22 14:59 ` Zoltan Hidvegi
  1996-07-22 16:23   ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Zoltan Hidvegi @ 1996-07-22 14:59 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-users

> I don't remember seeing a function like this posted before... it's for
> use with compctl and completes the second argument of cd, i.e. it
> tries to find a possible new directory by altering an occurrence of
> the existing cd argument in $PWD.

Have a look at Misc/compctl-examples and Functions/cdmatch2.  It is in the
zsh distribution since beta17, and it was in my private distribution much
before that.

Cheers,

Zoltan


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

* Re: completing second argument of cd
  1996-07-22 14:59 ` Zoltan Hidvegi
@ 1996-07-22 16:23   ` Bart Schaefer
  1996-07-22 18:11     ` Zoltan Hidvegi
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 1996-07-22 16:23 UTC (permalink / raw)
  To: Zoltan Hidvegi, Peter Stephenson, zsh-users

On Jul 22,  4:59pm, Zoltan Hidvegi wrote:
} Subject: Re: completing second argument of cd
}
} Have a look at Misc/compctl-examples and Functions/cdmatch2.

These examples would be a lot more helpful if they included some comments
explaining which of zsh's baroque parameter manipulation features they are
(ab)using, and why.  It's pretty obvious that Peter's function and Zoltan's
are both doing the same basic thing; but I have NO idea what reply[(r)]
in Zoltan's version means, since according to the documentation the (r)
should be followed by a pattern.

-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

New male in /home/schaefer:
>N  2 Justin William Schaefer  Sat May 11 03:43  53/4040  "Happy Birthday"


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

* Re: completing second argument of cd
  1996-07-22 16:23   ` Bart Schaefer
@ 1996-07-22 18:11     ` Zoltan Hidvegi
  0 siblings, 0 replies; 4+ messages in thread
From: Zoltan Hidvegi @ 1996-07-22 18:11 UTC (permalink / raw)
  To: schaefer; +Cc: pws, zsh-users

> On Jul 22,  4:59pm, Zoltan Hidvegi wrote:
> } Subject: Re: completing second argument of cd
> }
> } Have a look at Misc/compctl-examples and Functions/cdmatch2.
> 
> These examples would be a lot more helpful if they included some comments
> explaining which of zsh's baroque parameter manipulation features they are
> (ab)using, and why.  It's pretty obvious that Peter's function and Zoltan's
> are both doing the same basic thing; but I have NO idea what reply[(r)]
> in Zoltan's version means, since according to the documentation the (r)
> should be followed by a pattern.

There is a pattern, don't you see that :-) ?  There is an empty pattern.

The

[[ ${#reply[(r),-1]} != 0 ]] && reply[(r)]="''"

line just replaces an empty array element with a '' since zle_tricky does
not properly quotes empty strings.  Unfortunately replacing the empty sring
to '' in quotename() does not help since it messes up completion if there
is an empty string in the list.

Zoltan


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

end of thread, other threads:[~1996-07-22 18:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-07-22  8:36 completing second argument of cd Peter Stephenson
1996-07-22 14:59 ` Zoltan Hidvegi
1996-07-22 16:23   ` Bart Schaefer
1996-07-22 18:11     ` Zoltan Hidvegi

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