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

Completion for unknown command



I have a command I'd like to make completions work with. Unlike the other
unknown commands in the wiki this command doesn't complete with files, users,
hosts or arguments. It completes with values read/parsed from a file. The
command is 'cda' and is a zsh function wrapper around cdargs [1]. It is
autoloaded.

I originally thought I would be able to do the completion with a zstyle command
similar to adding ssh hosts. It used the default (all-files) which I didn't
want to extend, so I thought to change that. So I looked into using compdef to
change it from the default, but I couldn't find an appropriate builtin function
to use.

I ended up writing my own completion function to use with compdef [2].
This works, I just thought there would be a easier way to add the
completion via zstyles. Looking at what I have below, does anyone know of a
simpler way?

Thanks for any tips.


[1]
function cda () {
    cdargs -f $CDA_BOOKMARKS -o $CDA_RESULT "$1" && cd "`cat "$CDA_RESULT"`" ;
}


[2]
# $CDA_BOOKMARKS is an env var with the location of the bookmarks file used
# by cdargs.
_cda() { 
    local expl
    local -a cda_bookmarks
    cda_bookmarks=(${${(f)"$(<$CDA_BOOKMARKS)"}%%\ *})
    _wanted cda_bookmarks expl cda compadd -a cda_bookmarks 
}
compdef _cda cda


-- 

John Eikenberry
[jae@xxxxxxxx - http://zhar.net]
______________________________________________________________
"It is difficult to produce a television documentary that is both incisive
and probing when every twelve minutes one is interrupted by twelve dancing
rabbits singing about toilet paper." - Rod Serling



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