* re:[zash-3.0.0] bug in cdmatch for dirs w/ embedded space?
@ 1996-09-12 19:38 alain (a.) caron
1996-09-13 7:50 ` [zash-3.0.0] " Peter Stephenson
0 siblings, 1 reply; 2+ messages in thread
From: alain (a.) caron @ 1996-09-12 19:38 UTC (permalink / raw)
To: mdb; +Cc: zsh-workers
In message "[zash-3.0.0] bug in cdmatch for dirs w/ embedded space?",
'mdb@cdc.noaa.gov' writes:
>I'm trying to get zsh to complete a directory that has an embedded
>space, e.g., `foo bar' (personally I don't like them, but with
>mac/win95 filenames it seems to be pretty common to come across).
>
>I used the versions of compctl, cdmatch, and cdmatch2 distributed with
>zsh-3.0.0, and invoked zsh with the -f switch. It fails because too
>many backslashes get put in the completion, e.g.,
>
> % cd foo<TAB>
>results in
> % cd foo\\\ bar/
>
>Is there a more up to date cdmatch/compctl for this sort of thing? Or
>is there a (non-default) that needs to be set?
>
>Thanks.
>
>Here's exactly what I did:
>
>charney$ ~/bin/sunos-5.5/zsh-3.0.0 -f
>charney% echo $ZSH_VERSION
>3.0.0
>charney% ls
>foo bar
>charney% if [[ -o AUTO_REMOVE_SLASH ]] then
>then> compctl -x 'p[2]' -Q -K cdmatch2 - 'S[/][~][./][../]' -g '*(-/)' + \
>then> -g '*(-/D)' - 'n[-1,/], s[]' -K cdmatch -q -S '/' -- cd pushd
>then> else
>else> compctl -x 'p[2]' -Q -K cdmatch2 - 'S[/][~][./][../]' -g '*(-/)' + \
>else> -g '*(-/D)' - 'n[-1,/], s[]' -K cdmatch -S '/' -- cd pushd
>else> fi
>charney% fpath=(~/.zfunctions)
>charney% autoload cdmatch
>charney% autoload cdmatch2
>charney% cd foo\\\ bar/ # typed cd foo<TAB> here
>cd: no such file or directory: foo\ bar/
>charney% cd foo\ bar
>charney% pwd
>/tmp/mdb/foo bar
>charney% cat ~/.zfunctions/cdmatch
># Start of cdmatch.
># Save in your functions directory and autoload, then do
># compctl -x 'S[/][~][./][../]' -g '*(-/)' - \
># 'n[-1,/], s[]' -K cdmatch -S '/' -- cd pushd
>#
># Completes directories for cd, pushd, ... anything which knows about cdpath.
># You do not have to include `.' in your cdpath.
>#
># It works properly only if $ZSH_VERSION > 2.6-beta2. For erarlier versions
># it still works if RC_EXPAND_PARAM is not set or when cdpath is empty.
>local narg pref cdp
>read -nc narg
>read -Ac pref
>cdp=(. $cdpath)
>reply=( ${^cdp}/${pref[$narg]%$2}*$2(-/DN^M:t:gs/ /\\\\ /) )
replace this last line by:
reply=( ${^cdp}/${pref[$narg]%$2}*$2(-/DN^M:t) )
and everything should work fine. At least, it does for me.
>return
># End of cdmatch.
>charney% cat ~/.zfunctions/cdmatch2
># This function should be called from compctl to complete the
># second argument of cd and pushd.
>local from
>read -Ac from
>from="${from[2]}"
>eval "reply=( \${PWD:s@$from@$1*$2@}~$PWD(ND-/:) )"
>reply=( "${${reply[@]#${PWD%%$from*}}%${PWD#*$from}}" )
>[[ ${#reply[(r),-1]} != 0 ]] && reply[(r)]="''"
>return
>charney%
>charney$
>
>--
> -mb-
>
Regards,
Alain Caron
Nortel Technology, Montr?al, Qu?bec, Canada
email: alainc@nortel.ca
phone: 514-765-7718 or ESN 852-7718
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [zash-3.0.0] bug in cdmatch for dirs w/ embedded space?
1996-09-12 19:38 re:[zash-3.0.0] bug in cdmatch for dirs w/ embedded space? alain (a.) caron
@ 1996-09-13 7:50 ` Peter Stephenson
0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 1996-09-13 7:50 UTC (permalink / raw)
To: Zsh hackers list
"alain (a.) caron" wrote:
> >reply=( ${^cdp}/${pref[$narg]%$2}*$2(-/DN^M:t:gs/ /\\\\ /) )
>
> replace this last line by:
>
> reply=( ${^cdp}/${pref[$narg]%$2}*$2(-/DN^M:t) )
Yes, this works. However, this version of cdmatch has the (for me at
least) critical limitation that it doesn't handle subdirectories, just
the first one below the directory in $cdpath. I've gone back to a
previous version of cdmatch and applied the same treatment, which
works there too, so the following is what I'm using at the moment.
Sorry, I can't remember who wrote this one originally.
The compctl instructions at the top of the other one still apply,
though I find it simpler to see if ordinary completion will find a
directory, and only then use cdmatch:
compctl -g '*(-/)' + -K cdmatch -S / -q cd pushd
###############################################################################
# cdmatch - directory matching for cd
#
# Save in your functions directory and autoload, then do
# compctl -K cdmatch -S / -q + -g '*(D-/)' cd pushd
#
# Completes directories using cdpath (as cd does). . is automatically
# included, because cd works that way.
#
# If an absolute path is being specified, or cdpath is blank, the completion is
# left up to the shell. This results in such completions having a different
# look from those done by cdmatch itself. Hopefully a future version of zsh
# will rectify this in some way.
local notonlydot npos args pref dir d
reply=()
# check for cdpath empty or only containing .
for dir in $cdpath; do [[ $dir != . ]] && notonlydot=1; done
if [[ $notonlydot != 1 ]]; then return; fi
# get word on which completion is requested
read -nc npos
read -Ac args
# check for absolute path - watch out for erroneous ~ expansion
pref=x$args[$npos]
if [[ $pref[2] = [/\~] ]]; then return; fi
# relative path - use cdpath
pref=$args[$npos]
for dir in . $cdpath; do
for d in $dir/$pref*(ND-/:s,$dir/,,); do
reply=( $reply ${d%%/#} )
done
done
return
###############################################################################
--
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] 2+ messages in thread
end of thread, other threads:[~1996-09-13 8:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-09-12 19:38 re:[zash-3.0.0] bug in cdmatch for dirs w/ embedded space? alain (a.) caron
1996-09-13 7:50 ` [zash-3.0.0] " Peter Stephenson
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).