zsh-users
 help / color / mirror / code / Atom feed
From: Goran Koruga <goran.koruga@hermes.si>
To: zsh-users@sunsite.dk
Subject: Question about completion
Date: Tue, 18 Sep 2001 14:32:51 +0200	[thread overview]
Message-ID: <20010918143251.I31900@isis.hermes.si> (raw)

Hi all,

I am working on a programmable completion for ClearCase (versioning
system ala CVS but commercial and more advanced). I have used _cvs file,
distributed with zsh 4.0.2, as an example. cleartool command is similar
to cvs command in a way. Unlike cvs, it accepts no switches, so I am not
sure if I can take the cvs example directly.

So far I have done the following :

---------------------------- cut ---------------------------
#compdef cleartool

# redefine _cleartool.
_cleartool () {
  _arguments -s \
    '*::clearcase command:_cc_command'
}

# define cleartool command dispatch function.

(( $+functions[_cc_command] )) ||
_cc_command () {
  if (( ! $+_cc_cmds )); then
    typeset -gA _cc_cmds
    _cc_cmds=()
    for a in annotate apropos catcs checkin checkout chevent describe diff \
             edcs find findmerge help hostinfo ln ls lscheckout lsdo       \
             lshistory lsprivate lsview lsvtree man merge mkbranch mkdir   \
             mkelem mklabel mklbtype mkview mount mv protect pwv rename    \
             rmbranch rmelem rmlabel rmver setcs setview umount uncheckout
    do
      _cc_cmds[$a]=" "
    done
    _cc_cmds[checkin]=" ci "
    _cc_cmds[checkout]=" co "
    _cc_cmds[lscheckout]=" lsco "
    _cc_cmds[uncheckout]=" unco "
  fi

  if (( CURRENT == 1 )); then
    _tags commands && { compadd "$@" -k _cc_cmds || compadd "$@" ${(kv)=_cc_cmds
} }
  else
    local curcontext="$curcontext"

    cmd="${${(k)_cc_cmds[(R)* $words[1] *]}:-${(k)_cc_cmds[(i)$words[1]]}}"
    if (( $#cmd )); then
      curcontext="${curcontext%:*:*}:cc-${cmd}:"
      _cc_$cmd
    else
      _message "unknown clearcase command: $words[1]"
    fi
  fi
}

# define completion functions for each cvs command

(( $+functions[_cc_annotate] )) ||
_cc_annotate () {
  _arguments -s \
    '-all[include all lines]' \
    '-rm[include removed lines]' \
    '-nco[use non checked-out version]' \
    '(-s)-short[use annotation format strings that yield an abbreviated report]'
 \
    '(-l)-long[use annotation format strings that yield a verbose report]' \
    '-fmt+[specify display format]:display format:' \
    '(-rmf)-rmfmt+[specify a format for deletion annotations]:deletion format:' 
\
    '(-f)-force[display even duplicated annotation lines]' \
    '(-nhe)-nheader[suppress the header section]' \
    '(-nda)-ndata[suppress the annotated text lines]' \
    '*:cc file:_cc_files'
}

(( $+functions[_cc_apropos] )) ||
_cc_apropos () {
  _arguments -s \
    '(-glo)-glossary+[show header lines that match entire string]'
}

(( $+functions[_cc_catcs] )) ||
_cc_catcs () {
  _arguments -s \
    '-tag+[show config specs for given view-tag]:cc view:_cc_views'
}

# define completion functions for files in clearcase

(( $+functions[_cc_views] )) ||
_cc_views () {
  _wanted ccviews expl 'cc view' compadd - ${(@)${(@)${(@f)"$(cleartool lsview)"}#[ *][ ]}/ *}
}

(( $+functions[_cc_files] )) ||
_cc_files () {
  _wanted ccfiles expl 'cc file' compadd - ${(@)${(@M)${(@f)"$(cleartool ls)"}:#* Rule:*-mkbranch *}/@@*}
}

(( $+functions[_cc_co_files] )) ||
_cc_co_files() {
  _wanted ccfilesco expl 'cc file (checked-out)' compadd - ${(@)${(@f)"$(cleartool lsprivate -co)"}/ *}
}
---------------------------- cut ---------------------------

This somehow works. However I get unexepected behaviour when I type the
following :

cleartool annotate -<ctrl-d>

This is where all options should be listed. They get listed, but my
problem is, that also _cc_files completion is attempted. Is there a way
to overcome this ? What I am looking for, is to complete options and only
options if string starts with '-'.

My second question is more complicated. In ClearCase, one can access
different version of file with syntax like this : filename@@version,
where version is /main/1 for example. So full path for a file may look
like "foo@@/main/1". Right now, my completion lists only the filenames,
that is, only "foo" is listed. Is there a way to program completion so
that if a strng ends with "@@", I could run a custom function which would
list all the versions available ? I have looked at the manual pages and
examples, but I can't figure this out.

Hopefully this is not too long and indescriptive.

Thank you in advance.

Regards,
Goran
--

Writing about music is like dancing about architecture.
    -- Frank Zappa 


             reply	other threads:[~2001-09-18 12:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-18 12:32 Goran Koruga [this message]
2001-09-18 12:46 ` Daniel Brahneborg
2001-09-18 12:54   ` Goran Koruga
2001-09-18 13:41     ` Goran Koruga
2001-09-21 14:32 Felix Rosencrantz
2001-10-12  6:55 Question about Completion Felix Rosencrantz
2001-10-12 11:35 ` Goran Koruga

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=20010918143251.I31900@isis.hermes.si \
    --to=goran.koruga@hermes.si \
    --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).