* Zstyle trick for always adding fake filenames
@ 2000-09-06 6:57 Felix Rosencrantz
0 siblings, 0 replies; only message in thread
From: Felix Rosencrantz @ 2000-09-06 6:57 UTC (permalink / raw)
To: zsh-users
Here's a style trick I'm using and think others might find useful. It seems
little tricks like this might be suited for some sort of zsh cookbook, but
there isn't one, so I'm sending it the zsh-users to be archived.
Problem: You want to add fake file and directory names to completion for all
filename completions regardless of what directory the completion may be
happening in.
Solution: Use ${PREFIX:h} in your reply.
reply=("${PREFIX:h}:fake1 fake2 fake3")
For example, when using configure I like to set the "--prefix" option to
include the version of the tool I'm configuring. Usually this directory
doesn't exist in the destination directory (e.g. /opt or /usr/local). Though
the component name is usually a part of the current working directory, many
times it ${PWD:t} (i.e. basename $PWD).
Which can be added using this zstyle command.
zstyle -e :completion::complete:configure:option--prefix-1:files fake
'reply=("${PREFIX:h}:${PWD:t}")'
Explanation:
-e says that the value of this style is determined by eval'ing
the this style's value and taking the value of the parameter
"reply" as the value to use.
Context value (:comple...prefix-1:files) was found with the
_complete_help ("^Xh") widget. binding and refers to the value
of the --prefix option.
fake is the style name to add names to the list of files being
completed. It has an array value. Each element of the array
has the format "directory:name1...nameN", where directory has
to match the directory that is being completed in. If the
directory matches then name1 through nameN are added to the
list of directories being added, even if no such files really exist.
reply=(...) This is how a "zstyle -e" communicates back to zsh
what the real value should be.
${PREFIX:h} PREFIX is the value of the path that the user has
already typed (or matched). The ":h" (e.g. dirname $PREFIX)
makes sure that we have a directory name that will match the directory
we are completing in for the purpose of adding fakes.
${PWD:t} returns "basename $PWD" just adding the component part.
-FR
__________________________________________________
Do You Yahoo!?
Yahoo! Mail - Free email you can access from anywhere!
http://mail.yahoo.com/
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2000-09-06 6:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-09-06 6:57 Zstyle trick for always adding fake filenames Felix Rosencrantz
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).