Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Zstyle trick for always adding fake filenames



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/



Messages sorted by: Reverse Date, Date, Thread, Author