zsh-users
 help / color / mirror / code / Atom feed
* How to strip off common prefix for array elements?
@ 1998-02-19 11:10 Andrej Borsenkow
  1998-02-19 20:11 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Andrej Borsenkow @ 1998-02-19 11:10 UTC (permalink / raw)
  To: Zsh users mailing list

Consider the case:

cdpath=(~ ~/src ~/build/mips)
cd zshTAB -> gives me zsh-3.1.2 which is O.K., but I don't have any chance
to cd into build, because ~/src stays in the way.

The problem amounts to:

array of possile completions:
  ~/src/zsh-3.1.2 ~/build/mips/zsh-3.1.2
array of directories
  ~ ~/src ~/build/mips
Now I have to find the longest prefix from $cdpath elements so, that
remaining parts of completions are still uniq. 

the best way I can think of involves quite tedious loops over first and
second array. I had a vague hope, that it could be done with ZSH's magic
in parameter substitution. BTW somebody has an idea of extensions to allow
this be done (in general way)?

I am referring to Zoltan's cdmatch function. Currently it is nice 
one-liner - can it do the above and still remain small?

-------------------------------------------------------------------------
Andrej Borsenkow 		Fax:   +7 (095) 252 01 05
SNI ITS Moscow			Tel:   +7 (095) 252 13 88

NERV:  borsenkow.msk		E-Mail: borsenkow.msk@sni.de
-------------------------------------------------------------------------



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

* Re: How to strip off common prefix for array elements?
  1998-02-19 11:10 How to strip off common prefix for array elements? Andrej Borsenkow
@ 1998-02-19 20:11 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 1998-02-19 20:11 UTC (permalink / raw)
  To: borsenkow.msk, Zsh users mailing list

On Feb 19,  2:10pm, Andrej Borsenkow wrote:
} Subject: How to strip off common prefix for array elements?
}
} Consider the case:
} 
} cdpath=(~ ~/src ~/build/mips)
} cd zshTAB -> gives me zsh-3.1.2 which is O.K., but I don't have any chance
} to cd into build, because ~/src stays in the way.

So what you're trying to do is use completion to disambiguate when two or
more cdpath directories have same-named subdirectories?

Try this variant:

# Start of cdmatch.
# Save in your functions directory and autoload, then do
# compctl -x 'S[/][~][./][../]' -g '*(-/)' - \
#         'n[-1,/], s[]' -K cdmatch -U -- 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 > 3.0-pre4.  Remove `emulate -R zsh'
# for all other values of $ZSH_VERSION > 2.6-beta2. For earlier versions
# it still works if RC_EXPAND_PARAM is not set or when cdpath is empty.
emulate -R zsh
setopt localoptions
local narg pref cdp

read -nc narg
read -Ac pref

cdp=(. $cdpath)
reply=( ${^cdp}/${pref[$narg]}*$2(-/DN^M) )

return
# End of cdmatch.

It could use some work, but the basic idea is that you don't remove any
prefixes, and use -U to replace the entire word with the full completion.
As is, the above is really only usable with menucomplete set, but it's a
start in the right direction.


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


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

end of thread, other threads:[~1998-02-19 20:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-02-19 11:10 How to strip off common prefix for array elements? Andrej Borsenkow
1998-02-19 20:11 ` 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).