From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from euclid.skiles.gatech.edu (list@euclid.skiles.gatech.edu [130.207.146.50]) by coral.primenet.com.au (8.7.5/8.7.3) with ESMTP id SAA10108 for ; Mon, 22 Jul 1996 18:40:34 +1000 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id EAA20107; Mon, 22 Jul 1996 04:38:32 -0400 (EDT) Resent-Date: Mon, 22 Jul 1996 04:37:25 -0400 (EDT) Message-Id: <199607220836.KAA28591@hydra.ifh.de> To: zsh-users@math.gatech.edu (Zsh users list) Subject: completing second argument of cd Date: Mon, 22 Jul 1996 10:36:21 +0200 From: Peter Stephenson Resent-Message-ID: <"R77TA3.0.bv4.4tpyn"@euclid> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/319 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu 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 -> 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 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.