zsh-users
 help / color / mirror / code / Atom feed
From: John Eikenberry <jae@zhar.net>
To: zsh users <zsh-users@sunsite.dk>
Subject: Completion for unknown command
Date: Wed, 17 May 2006 21:18:48 -0400	[thread overview]
Message-ID: <20060518011847.GA5095@mollari.zhar.net> (raw)


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@zhar.net - 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


                 reply	other threads:[~2006-05-18  1:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060518011847.GA5095@mollari.zhar.net \
    --to=jae@zhar.net \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).