zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH: Re: Completion/User functions again
@ 1999-07-14 12:46 Sven Wischnowsky
  1999-07-14 13:12 ` Tanaka Akira
  1999-07-14 14:29 ` Completion/User functions again Oliver Kiddle
  0 siblings, 2 replies; 6+ messages in thread
From: Sven Wischnowsky @ 1999-07-14 12:46 UTC (permalink / raw)
  To: zsh-workers


Oliver Kiddle wrote:

> Andrej Borsenkow wrote:
> > 
> >  - _tar and _find are hopelessly GNUish. You cannot expect, that users will
> > study every function to find out if it is applicable to there system. They will
> > simply install it and wonder why it does not work. Of course, gzip, configure
> > etc are GNU as well - but they do not conflict with system standard commands.
> 
> This is why I suggested a while ago that things such as tar and find are
> moved to a 'Gnu' directory and other directories such as Aix, Irix etc
> can contain completions specific to
> those systems.

I've been thinking about this for a long time, too. The problems are
that we would have to fill those directories (so that they don't look
silly) and with such directories users would expect to need only to
copy the contents of one such directory (or link User to it), so they
would have to be (almost) complete. That's a lot of work and who'll do 
that, I wonder.

While we are at it: we still don't have completion functions for some
commands for which we have compctl examples, e.g. cvs and rpm. I don't 
use either of these often enough to be able to write good functions
for them -- any volunteers for that?

> The patch to _x_options also
> causes it to only complete options on words starting with a '-'. I
> prefer to complete options this way as it keeps the number of matches
> down.

I never expected _x_options to survive this long... ;-)

> Maybe we should put a note in one of the readmes to make it clear that
> the functions may not work on all systems, maybe detailing which might
> have issues. I find many of the functions enormously useful and it would
> be a pity for them not to be used.

Maybe, yes.

> One thing which I just noticed which I don't think is right:
> rlogin <tab>
> zsh: do you wish to see all 114 possibilities? n
> The no returns to 'rlogin ' on the command-line. now, if I press tab
> again, menu completion
> starts. I think it should ignore the original tab if the question was
> answered with no.

Hm. 1) It has always been like that (or should have been). 2) Dunno,
you can always use ^D, but I don't have a real opinion about this --
anyone else wanting to comment?


Maybe we should add some kind of programming style guide some day,
containing things like `make functions that can be used as helper
functions do something useful with their arguments if possible' and
`do not use compgen if you're only after the -k or -s options'
(compadd is faster and -- I think -- cleaner for this).

Bye
 Sven

diff -u -r oc/User/_hosts Completion/User/_hosts
--- oc/User/_hosts	Tue Jul 13 10:58:41 1999
+++ Completion/User/_hosts	Wed Jul 14 14:32:29 1999
@@ -2,4 +2,4 @@
 
 : ${(A)hosts:=${(s: :)${(ps:\t:)${${(f)"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}}
 
-compgen -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' -k hosts
+compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" - "$hosts[@]"
diff -u -r oc/User/_x_options Completion/User/_x_options
--- oc/User/_x_options	Wed Jul 14 14:33:41 1999
+++ Completion/User/_x_options	Wed Jul 14 14:42:29 1999
@@ -3,7 +3,8 @@
 # A simple pattern completion, just as an example.
 
 if [ "$words[CURRENT-1]" = "-display" ]; then
-  ISUFFIX=':0' _hosts
+  _compskip=''
+  _hosts -S :0
 else
   compadd -P- -J options - display name xrm
 fi

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: Re: Completion/User functions again
  1999-07-14 12:46 PATCH: Re: Completion/User functions again Sven Wischnowsky
@ 1999-07-14 13:12 ` Tanaka Akira
  1999-07-20 18:05   ` CVS completer (Re: PATCH: Re: Completion/User functions again) Bart Schaefer
  1999-07-14 14:29 ` Completion/User functions again Oliver Kiddle
  1 sibling, 1 reply; 6+ messages in thread
From: Tanaka Akira @ 1999-07-14 13:12 UTC (permalink / raw)
  To: zsh-workers

In article <199907141246.OAA11798@beta.informatik.hu-berlin.de>,
  Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:

> While we are at it: we still don't have completion functions for some
> commands for which we have compctl examples, e.g. cvs and rpm. I don't 
> use either of these often enough to be able to write good functions
> for them -- any volunteers for that?

I wrote _cvs.
But it's ugly, not self-contained and it doesn't deal with CVS/Entries.
And I don't have a time to implove it in this week.

So, if another implementation exists, it may better.

---------- _cvs ----------
#compdef cvs

typeset -A short_opts

local com="${words[(i)(add|ad|new|admin|adm|rcs|annotate|ann|checkout|co|get|commit|ci|com|diff|di|dif|edit|editors|export|exp|ex|history|hi|his|import|im|imp|init|log|lo|rlog|login|logon|lgn|logout|rdiff|patch|release|re|rel|remove|rm|delete|status|st|stat|rtag|rt|rfreeze|tag|ta|freeze|unedit|update|up|upd|watch|watchers)]}"

local complete_D="compgen -k '(yesterday week\\ ago month\\ ago)'"
local complete_k="compgen -k '(kv kvl k o b v)'"
local complete_r="compgen -k '(tag)'"

#_view_completion_parameters "com=$com"

if (( $com < $CURRENT )); then
  case "$words[$com]" in
    add|ad|new) # "+k:m:"
      short_opts=(k: "$complete_k" m: "compgen -k '(MESSAGE)'")
      _complete_opts || compgen -f
      ;;
    admin|adm|rcs) # "+ib::c:a:A:e:l::u::LUn:N:m:o:s:t::IqxV:k:"
      short_opts=(i '' b:: '' c: '' a: '' A: '' e: '' l:: '' u:: '' L '' U '' n: '' N: '' m: '' o: '' s: '' t:: '' I '' q '' x '' V: '' k: '')
      _complete_opts || compgen -f
      ;;
    annotate|ann) # "+lr:D:fR"
      short_opts=(l '' r: '' D: '' f '' R '')
      _complete_opts || compgen -f
      ;;
    checkout|co|get) # "+ANnk:d:flRpQqcsr:D:j:P"
      short_opts=(A '' N '' n '' k: "$complete_k" d: '' f '' l '' R '' p '' Q '' q '' c '' s '' r: "$complete_r" D: "$complete_D" j: '' P '')
      _complete_opts || compgen -k '(MODULE)'
      ;;
    commit|ci|com) # "+nlRm:fF:r:"
      short_opts=(n '' l '' R '' m: '' f '' F: '' r: "$complete_r")
      _complete_opts || compgen -f
      ;;
    diff|di|dif) # "+abcdefhilnpstuw0123456789BHNRC:D:F:I:L:U:V:W:k:r:"
      short_opts=(a '' b '' c '' d '' e '' f '' h '' i '' l '' n '' p '' s '' t '' u '' w ''
        0 '' 1 '' 2 '' 3 '' 4 '' 5 '' 6 '' 7 '' 8 '' 9 '' B '' H '' N '' R ''
        C: '' D: "$complete_D" F: '' I: '' L: '' U: '' V: '' W: '' k: "$complete_k" r: "$complete_r")
      _complete_opts || compgen -f
      ;;
    edit) # "+lRa:"
      short_opts=(l '' R '' a: '')
      _complete_opts || compgen -f
      ;;
    editors) # "+lR"
      short_opts=(l '' R '')
      _complete_opts || compgen -f
      ;;
    export|exp|ex) # "+ANnk:d:flRpQqcsr:D:j:P"
      short_opts=(A '' N '' n '' k: "$complete_k" d: '' f '' l '' R '' p '' Q '' q '' c '' s '' r: "$complete_r" D: "$complete_D" j: '' P '')
      _complete_opts || compgen -k '(MODULE)'
      ;;
    history|hi|his) # "+Tacelow?D:b:f:m:n:p:r:t:u:x:X:z:"
      short_opts=(T '' a '' c '' e '' l '' o '' w '' \? '' D: "$complete_D" b: '' f: '' m: '' n: '' p: '' r: '' t: '' u: '' x: '' X: '' z: '')
      _complete_opts || compgen -f
      ;;
    import|im|imp) # "+Qqdb:m:I:k:W:"
      short_opts=(Q '' q '' d '' b: '' m: '' I: '' k: '' W: '')
      _complete_opts || compgen -k '(REPOSITORY-VENDORTAG-RELEASETAG)'
      ;;
    init)
      short_opts=()
      _complete_opts || compgen -f
      ;;
    login|logon|lgn)
      short_opts=()
      _complete_opts || compgen -f
      ;;
    logout)
      short_opts=()
      _complete_opts || compgen -f
      ;;
    rdiff|patch|pa) # "+V:k:cuftsQqlRD:r:"
      short_opts=(V: '' k: "$complete_k" c '' u '' f '' t '' s '' Q '' q '' l '' R '' D: "$complete_D" r: "$complete_r")
      _complete_opts || compgen -f
      ;;
    release|re|rel) # "+Qdq"
      short_opts=(Q '' d '' q '')
      _complete_opts || compgen -f
      ;;
    remove|rm|delete) # "+flR"
      short_opts=(f '' l '' R '')
      _complete_opts || compgen -f
      ;;
    status|st|stat) # "+vlR"
      short_opts=(v '' l '' R '')
      _complete_opts || compgen -f
      ;;
    tag|ta|freeze) # "+FQqlRcdr:D:bf"
      short_opts=(F '' Q '' q '' l '' R '' c '' d '' r: "$complete_r" D: "$complete_D" b '' f '')
      _complete_opts || compgen -f
      ;;
    unedit) # "+lR"
      short_opts=(l '' R '')
      _complete_opts || compgen -f
      ;;
    update|up|upd) # "+ApPflRQqduk:r:D:j:I:W:"
      short_opts=(A '' p '' P '' f '' l '' R '' Q '' q '' d '' u '' k: "$complete_k" r: "$complete_r" D: "$complete_D" j: '' I: '' W: '')
      _complete_opts || compgen -f
      ;;
    watch)
      if [[ $CURRENT = $(($com + 1)) ]]; then
        compgen -k '(on off add remove)'
      else
        case "$words[$com+1]" in
          on|off) # "+lR"
            short_opts=(l '' R '')
            _complete_opts || compgen -f
            ;;
          add|remove) # "+lRa:"
            short_opts=(l '' R '' a: '')
            _complete_opts || compgen -f
            ;;
        esac
      fi
      ;;
    watchers) # "+lR"
      short_opts=(l '' R '')
      _complete_opts || compgen -f
      ;;
    *) compgen -f;;
  esac
  return
fi

case ${+cvs_roots} in
  0)
    cvs_roots=()
    if [[ -f ~/.cvspass ]]; then
      cvs_roots=(
	$(cut -d ' ' -f 1 ~/.cvspass)
      )
    fi
    ;;
esac

short_opts=(
  H '' Q '' q '' r '' w '' l '' n '' t '' v '' f '' a ''
  b: "compgen -k '(/usr/local/bin)'"
  T: "compgen -k '(/tmp)'"
  e: "compgen -k '(vi)'"
  d: "compgen -k cvs_roots || compgen -/"
  z: "compgen -k '(9)'"
  s: "_cvs_user_variable"
)

_complete_opts || 
compgen -k '(add admin annotate checkout commit
             diff edit editors export history
             import init log login logout
             rdiff release remove status rtag
             tag unedit update watch watchers)' ||
compgen -k '(add ad new              admin adm rcs           annotate ann
             checkout co get         commit ci com           diff di dif
             edit                    editors                 export exp ex
             history hi his          import im imp           init
             log lo rlog             login logon lgn         logout
             rdiff patch             release re rel          remove rm delete
             status st stat          rtag rt rfreeze         tag ta freeze
             unedit                  update up upd           watch
             watchers)'

------------------------------

---------- _complete_opts ----------
#autoload

# Usage:
#  typeset -A short_opts
#  short_opts=(
#    H '' 
#    f 'compgen -f'
#  )
#  _complete_opts

typeset -a no_arg with_arg
no_arg=($short_opts[(I)?])
with_arg=($short_opts[(I)?:]:s/://)

case "${#no_arg}-${#with_arg}" in
  0-0)
    if [[ x$PREFIX = x-* ]]; then
      compgen -k '()'
    else
      false
    fi
    ;;

  0-*)
    if [[ x$PREFIX = x- ]]; then
      IPREFIX="$IPREFIX$PREFIX"
      PREFIX=
      compgen -k with_arg
    elif [[ x$PREFIX = x-[${(j::)with_arg}] ]]; then
      IPREFIX="$IPREFIX$PREFIX"
      PREFIX=
      eval $short_opts[$IPREFIX[-1]:]
    elif [[ x$PREFIX = x-[${(j::)with_arg}]* ]]; then
      local p="$PREFIX[1,(r)[${(j::)with_arg}]]"
      IPREFIX="$IPREFIX$p"
      PREFIX="$PREFIX[$#p + 1,-1]"
      eval $short_opts[$IPREFIX[-1]:]
    elif [[ x$words[$CURRENT-1] = x-[${(j::)with_arg}] ]]; then
      local p="$words[$CURRENT - 1]"
      eval $short_opts[$p[-1]:]
    else
      false
    fi
    ;;

  *-0)
    if [[ x$PREFIX = x-[${(j::)no_arg}]# ]]; then
      IPREFIX="$IPREFIX$PREFIX"
      PREFIX=
      compgen -k no_arg
    else
      false
    fi
    ;;

  *-*)
    if [[ x$PREFIX = x-[${(j::)no_arg}]# ]]; then
      IPREFIX="$IPREFIX$PREFIX"
      PREFIX=
      compgen -k no_arg
      compgen -k with_arg
    elif [[ x$PREFIX = x-[${(j::)no_arg}]#[${(j::)with_arg}] ]]; then
      IPREFIX="$IPREFIX$PREFIX"
      PREFIX=
      eval $short_opts[$IPREFIX[-1]:]
    elif [[ x$PREFIX = x-[${(j::)no_arg}]#[${(j::)with_arg}]* ]]; then
      local p="$PREFIX[1,(r)[${(j::)with_arg}]]"
      IPREFIX="$IPREFIX$p"
      PREFIX="$PREFIX[$#p + 1,-1]"
      eval $short_opts[$IPREFIX[-1]:]
    elif [[ x$words[$CURRENT-1] = x-[${(j::)no_arg}]#[${(j::)with_arg}] ]]; then
      local p="$words[$CURRENT - 1]"
      eval $short_opts[$p[-1]:]
    else
      false
    fi
    ;;
esac
------------------------------

Also, I wrote _wget, _lynx, etc. If you interest them, See
http://www.ldl.jaist.ac.jp/~akr/zsh/dot-zsh/funcs/.

I want standard way to specify user's completion preferences such as
host-port relation for _telnet and _socket, URLs for _wget and _lynx,
user-host relation for _finger, and so on.
-- 
Tanaka Akira


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Completion/User functions again
  1999-07-14 12:46 PATCH: Re: Completion/User functions again Sven Wischnowsky
  1999-07-14 13:12 ` Tanaka Akira
@ 1999-07-14 14:29 ` Oliver Kiddle
  1 sibling, 0 replies; 6+ messages in thread
From: Oliver Kiddle @ 1999-07-14 14:29 UTC (permalink / raw)
  To: zsh-workers

Sven Wischnowsky wrote:

> I've been thinking about this for a long time, too. The problems are
> that we would have to fill those directories (so that they don't look

I don't think it would matter too much if they were on the empty side
while we are still on version 3.1.x.

> silly) and with such directories users would expect to need only to
> copy the contents of one such directory (or link User to it), so they
> would have to be (almost) complete. That's a lot of work and who'll do
> that, I wonder.

Linking User to the directory probably wouldn't be the best approach
because there are many commands for which the completion won't be system
specific. I would go for an approach similar to that for installing
modules so users can add directories to install to a file listing the
completion directories. The configure script could possibly be enhanced
to intelligently add any appropriate directories. I would also subdivide
the User directory a little. For example if all the X programs were in
their own directory then they could be excluded on a system which lacks
X. We might later add directories for obscure software which would only
be relevant to a small number of users. This is a large reason why I
prefer the directories to be preserved with the installation (via
--enable-function-subdirs) and think it should be the default.

> While we are at it: we still don't have completion functions for some
> commands for which we have compctl examples, e.g. cvs and rpm. I don't
> use either of these often enough to be able to write good functions
> for them -- any volunteers for that?

I don't use rpm or cvs either so I won't volunteer for those but there
are many other programs for which I plan to write completions - I had an
enormous number of tcsh completes which I have yet to convert to zsh.
I've got a few IRIX/AIX specific ones which I'll contribute if and when
we have directories set up to accomodate them.

> Maybe we should add some kind of programming style guide some day,
> containing things like `make functions that can be used as helper
> functions do something useful with their arguments if possible' and
> `do not use compgen if you're only after the -k or -s options'
> (compadd is faster and -- I think -- cleaner for this).

A programming style guide would certainly be a good idea and its
usefulness would not be limited to writing zsh completions. It might be
a good idea to start one off as a simple text file, listing key points
particularly any which aren't immediately obvious like the compadd
point. We can always convert it to LaTeX/yodl/texinfo/whatever and
expand it into a readable document later.

Oliver Kiddle


^ permalink raw reply	[flat|nested] 6+ messages in thread

* CVS completer (Re: PATCH: Re: Completion/User functions again)
  1999-07-14 13:12 ` Tanaka Akira
@ 1999-07-20 18:05   ` Bart Schaefer
  1999-07-26  0:52     ` Tanaka Akira
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 1999-07-20 18:05 UTC (permalink / raw)
  To: Tanaka Akira; +Cc: zsh-workers

On Jul 14, 10:12pm, Tanaka Akira wrote:
} Subject: Re: PATCH: Re: Completion/User functions again
}
} > While we are at it: we still don't have completion functions for some
} > commands for which we have compctl examples, e.g. cvs and rpm.
} 
} I wrote _cvs.
} But it's ugly, not self-contained and it doesn't deal with CVS/Entries.
} And I don't have a time to implove it in this week.

Below is an improved version of Tanaka's _cvs completer.  I changed many
"compgen -[sk]" calls into compadd calls, fixed up completing of option
letters in a couple of cases, and used the explanation-printing trick
recently discussed on zsh-users in a couple of others.  And I changed
_complete_opts to take the list of options and completion actions as
commmand-line arguments rather than through a shared global association.

However, there is still much room for improvement; for example, the
explanation strings get confused after "cvs import" if there are any
intervening options between the word "import" and the repository name.
I simply don't have time to beat on it any longer.

Also, some options like -k require that there be no space between the
option and its arguments, but nothing seems to enforce that -- even if
I type "cvs add -kv <TAB>" (note space after -kv) the completions I get
are the ones for -k; it should instead act as if a new option or file
name were being completed.

Finally, there are a number of cases where "compgen -f" could be replaced
by something similar to the cvstargets function from misc/compctl-examples.

There are some fairly long lines below, so watch out for wrapping.

--- 8< --- _cvs --- 8< ---
#compdef cvs

typeset -A commands
commands=(add "ad new"            admin "adm rcs"         annotate ann
          checkout "co get"       commit "ci com"         diff "di dif"
          edit ""                 editors ""              export "exp ex"
          history "hi his"        import "im imp"         init ""
          log "lo rlog"           login "logon lgn"       logout ""
          rdiff patch             release "re rel"        remove "rm delete"
          status "st stat"        rtag "rt rfreeze"       tag "ta freeze"
          unedit ""               update "up upd"         watch ""
          watchers "")

local com="${words[(i)(${(j:|:)${(kv)=commands}})]}"

local showlist='compstate[list]=list; compstate[force_list]=yes'
local showhint="$showlist ; compstate[insert]=''"
local complete_D="compadd yesterday week\\ ago month\\ ago"
local complete_k="compadd kv kvl k o b v"
local complete_r="compadd -UX 'Enter tag name or rev number' ''; $showhint"
local complete_m="compadd -UX 'Enter log message' -n ''; $showhint"

#_view_completion_parameters "com=$com"

if (( $com < $CURRENT )); then
  case "$words[$com]" in
    add|ad|new) # "+k:m:"
      _complete_opts k: "$complete_k" m: "$complete_m" || compgen -f
      ;;
    admin|adm|rcs) # "+ib::c:a:A:e:l::u::LUn:N:m:o:s:t::IqxV:k:"
      _complete_opts i '' b:: '' c: '' a: '' A: '' e: '' l:: '' u:: '' L '' U '' n: '' N: '' m: "$complete_m" o: '' s: '' t:: '' I '' q '' x '' V: '' k: "$complete_k" || compgen -f
      ;;
    annotate|ann) # "+lr:D:fR"
      _complete_opts l '' r: '' D: '' f '' R '' || compgen -f
      ;;
    checkout|co|get) # "+ANnk:d:flRpQqcsr:D:j:P"
      _complete_opts A '' N '' n '' k: "$complete_k" d: '' f '' l '' R '' p '' Q '' q '' c '' s '' r: "$complete_r" D: "$complete_D" j: '' P '' || compadd MODULE
      ;;
    commit|ci|com) # "+nlRm:fF:r:"
      _complete_opts n '' l '' R '' m: "$complete_m" f '' F: '' r: "$complete_r" || compgen -f
      ;;
    diff|di|dif) # "+abcdefhilnpstuw0123456789BHNRC:D:F:I:L:U:V:W:k:r:"
      _complete_opts a '' b '' c '' d '' e '' f '' h '' i '' l '' n '' p '' s '' t '' u '' w '' 0 '' 1 '' 2 '' 3 '' 4 '' 5 '' 6 '' 7 '' 8 '' 9 '' B '' H '' N '' R '' C: '' D: "$complete_D" F: '' I: '' L: '' U: '' V: '' W: '' k: "$complete_k" r: "$complete_r" || compgen -f
      ;;
    edit) # "+lRa:"
      _complete_opts l '' R '' a: '' || compgen -f
      ;;
    editors) # "+lR"
      _complete_opts l '' R '' || compgen -f
      ;;
    export|exp|ex) # "+ANnk:d:flRpQqcsr:D:j:P"
      _complete_opts A '' N '' n '' k: "$complete_k" d: '' f '' l '' R '' p '' Q '' q '' c '' s '' r: "$complete_r" D: "$complete_D" j: '' P '' || compadd MODULE
      ;;
    history|hi|his) # "+Tacelow?D:b:f:m:n:p:r:t:u:x:X:z:"
      _complete_opts T '' a '' c '' e '' l '' o '' w '' \? '' D: "$complete_D" b: '' f: '' m: "$complete_m" n: '' p: '' r: '' t: '' u: '' x: '' X: '' z: '' || compgen -f
      ;;
    import|im|imp) # "+Qqdb:m:I:k:W:"
      _complete_opts Q '' q '' d '' b: '' m: "$complete_m" I: '' k: "$complete_k" W: '' || case $[CURRENT-com] in
	1) compgen -X "Enter repository name" -W $CVSROOT -g '*~*CVSROOT(/)' -s '';;
	2) compadd -UX "Enter vendor tag name" -n '' && eval "$showhint";;
	3) compadd -UX "Enter release tag name" -n '' && eval "$showhint";;
	*) compadd -UX "No futher arguments used" -n '' && eval "$showhint";;
	esac
      ;;
    init)
      break
      ;;
    login|logon|lgn)
      _complete_opts || compgen -f
      ;;
    logout)
      _complete_opts || compgen -f
      ;;
    rdiff|patch|pa) # "+V:k:cuftsQqlRD:r:"
      _complete_opts V: '' k: "$complete_k" c '' u '' f '' t '' s '' Q '' q '' l '' R '' D: "$complete_D" r: "$complete_r" || compgen -f
      ;;
    release|re|rel) # "+Qdq"
      _complete_opts Q '' d '' q '' || compgen -/
      ;;
    remove|rm|delete) # "+flR"
      _complete_opts f '' l '' R '' || compgen -f
      ;;
    status|st|stat) # "+vlR"
      _complete_opts v '' l '' R '' || compgen -f
      ;;
    tag|ta|freeze) # "+FQqlRcdr:D:bf"
      _complete_opts F '' Q '' q '' l '' R '' c '' d '' r: "$complete_r" D: "$complete_D" b '' f '' || compgen -f
      ;;
    unedit) # "+lR"
      _complete_opts l '' R '' || compgen -f
      ;;
    update|up|upd) # "+ApPflRQqduk:r:D:j:I:W:"
      _complete_opts A '' p '' P '' f '' l '' R '' Q '' q '' d '' u '' k: "$complete_k" r: "$complete_r" D: "$complete_D" j: '' I: '' W: '' || compgen -f
      ;;
    watch)
      if (( CURRENT == com + 1 )); then
        compadd on off add remove
      else
        case "$words[com+1]" in
          on|off) # "+lR"
            _complete_opts l '' R '' || compgen -f
            ;;
          add|remove) # "+lRa:"
            _complete_opts l '' R '' a: '' || compgen -f
            ;;
        esac
      fi
      ;;
    watchers) # "+lR"
      _complete_opts l '' R '' || compgen -f
      ;;
    *) compgen -f;;
  esac
  return
fi

case ${+cvs_roots} in
  0)
    cvs_roots=()
    if [[ -f ~/.cvspass ]]; then
      cvs_roots=(
	$(cut -d ' ' -f 1 ~/.cvspass)
      )
    fi
    ;;
esac

_complete_opts \
  H '' Q '' q '' r '' w '' l '' n '' t '' v '' f '' a '' \
  b: "compadd /usr/local/bin" \
  T: "compadd $TMPPREFIX:h $TMPDIR /tmp" \
  e: "compadd vi" \
  d: "compadd $cvs_roots || compgen -/" \
  z: "compadd 9'" \
  s: "_cvs_user_variable" \
 || 
compadd ${(k)commands} ||
compadd ${(kv)=commands}

--- 8< --- end of _cvs --- 8< ---
--- 8< --- _complete_opts --- 8< ---

#autoload

# Usage:
#  _complete_opts H '' f 'compgen -f'

emulate -L zsh
setopt extendedglob

typeset -A option_pairs
option_pairs=("$@")
typeset -a no_arg with_arg opt_arg
no_arg=($option_pairs[(I)?])
opt_arg=($option_pairs[(I)?::]:s/:://)
with_arg=($option_pairs[(I)?:]:s/:// $opt_arg)

case "${#no_arg}-${#with_arg}" in
  0-0)
    if [[ x$PREFIX = x-* ]]; then
      compgen -k '()'			# What does this accomplish?
    else
      false
    fi
    ;;

  0-*)
    if [[ x$PREFIX = x- ]]; then
      IPREFIX="$IPREFIX$PREFIX"
      PREFIX=
      compadd $with_arg
    elif [[ x$PREFIX = x-[${(j::)with_arg}] ]]; then
      IPREFIX="$IPREFIX$PREFIX"
      PREFIX=
      eval $option_pairs[$IPREFIX[-1]:]
    elif [[ x$PREFIX = x-[${(j::)with_arg}]* ]]; then
      local p="$PREFIX[1,(r)[${(j::)with_arg}]]"
      IPREFIX="$IPREFIX$p"
      PREFIX="$PREFIX[$#p + 1,-1]"
      eval $option_pairs[$IPREFIX[-1]:]
    elif [[ x$words[$CURRENT-1] = x-[${(j::)with_arg}] ]]; then
      local p="$words[$CURRENT - 1]"
      eval $option_pairs[$p[-1]:]
    else
      false
    fi
    ;;

  *-0)
    if [[ x$PREFIX = x-[${(j::)no_arg}]# ]]; then
      IPREFIX="$IPREFIX$PREFIX"
      PREFIX=
      compadd $no_arg
    else
      false
    fi
    ;;

  *-*)
    if [[ x$PREFIX = x-[${(j::)no_arg}]# ]]; then
      IPREFIX="$IPREFIX$PREFIX"
      PREFIX=
      compadd $no_arg
      compadd $with_arg
    elif [[ x$PREFIX = x-[${(j::)no_arg}]#[${(j::)with_arg}] ]]; then
      IPREFIX="$IPREFIX$PREFIX"
      PREFIX=
      eval $option_pairs[$IPREFIX[-1]:]
    elif [[ x$PREFIX = x-[${(j::)no_arg}]#[${(j::)with_arg}]* ]]; then
      local p="$PREFIX[1,(r)[${(j::)with_arg}]]"
      IPREFIX="$IPREFIX$p"
      PREFIX="$PREFIX[$#p + 1,-1]"
      eval $option_pairs[$IPREFIX[-1]:]
    elif [[ x$words[$CURRENT-1] = x-[${(j::)no_arg}]#[${(j::)with_arg}] ]]; then
      local p="$words[$CURRENT - 1]"
      eval $option_pairs[$p[-1]:]
    else
      false
    fi
    ;;
esac || { compadd - -${(k)^option_pairs:gs/://} && false }

--- 8< --- end of _complete_opts --- 8< ---

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: CVS completer (Re: PATCH: Re: Completion/User functions again)
  1999-07-20 18:05   ` CVS completer (Re: PATCH: Re: Completion/User functions again) Bart Schaefer
@ 1999-07-26  0:52     ` Tanaka Akira
  0 siblings, 0 replies; 6+ messages in thread
From: Tanaka Akira @ 1999-07-26  0:52 UTC (permalink / raw)
  To: zsh-workers

I think _complete_opts is bit verbose.

--- Completion/Base/_complete_opts-	Mon Jul 26 09:45:51 1999
+++ Completion/Base/_complete_opts	Mon Jul 26 09:46:49 1999
@@ -81,7 +81,9 @@
 esac
 
 if [[ -z "$done" ]]; then
-  compadd - -${(k)^option_pairs:gs/://}
+  if (( $+complete_opts_verbose )); then
+    compadd - -${(k)^option_pairs:gs/://}
+  fi
   false
 else
   true

-- 
Tanaka Akira


^ permalink raw reply	[flat|nested] 6+ messages in thread

* PATCH: Re: Completion/User functions again
  1999-07-14 10:37 Andrej Borsenkow
@ 1999-07-14 12:09 ` Oliver Kiddle
  0 siblings, 0 replies; 6+ messages in thread
From: Oliver Kiddle @ 1999-07-14 12:09 UTC (permalink / raw)
  To: Andrej Borsenkow; +Cc: ZSH workers mailing list

Andrej Borsenkow wrote:
> 
>  - _tar and _find are hopelessly GNUish. You cannot expect, that users will
> study every function to find out if it is applicable to there system. They will
> simply install it and wonder why it does not work. Of course, gzip, configure
> etc are GNU as well - but they do not conflict with system standard commands.

This is why I suggested a while ago that things such as tar and find are
moved to a 'Gnu' directory and other directories such as Aix, Irix etc
can contain completions specific to
those systems.

>  - _hosts, _rlogin, _x_options are using array hosts. This most probably does
> not exist. Again, I do not like installing something that does not work
> out-of-the-box by default. This should be done explicitly in hope, that users
> understand what's going on :-)

This is why I changed _hosts to generate a hosts array from /etc/hosts
if $hosts is unset. This may not work perfectly on all systems but it's
better than just assuming $hosts is set and can always be improved
later. Following is a patch so _rlogin and _x_options use _hosts - I
must have forgotten to do this before. The patch to _x_options also
causes it to only complete options on words starting with a '-'. I
prefer to complete options this way as it keeps the number of matches
down.

>  - _chown, _chgrp, _stty are too system dependent. It is better to not provide
> completion at all than provide completion that only partially works. I do not
> suggest removing them from distribution - but to not install them by default.

chown and chgrp will work on the vast majority of systems. They could
certainly be improved to generate a more reliable list of groups though.
Maybe stty can be improved by parsing the output of stty -a.

> To summarise - I firmly believe, that everything that gets installed must work
> "as is" on every system. Anything that works only on some systems or something
> that needs additional setup should only be installed explicitly.

Maybe we should put a note in one of the readmes to make it clear that
the functions may not work on all systems, maybe detailing which might
have issues. I find many of the functions enormously useful and it would
be a pity for them not to be used.

One thing which I just noticed which I don't think is right:
rlogin <tab>
zsh: do you wish to see all 114 possibilities? n
The no returns to 'rlogin ' on the command-line. now, if I press tab
again, menu completion
starts. I think it should ignore the original tab if the question was
answered with no.

Oliver Kiddle

*** Completion/User/_rlogin.old	Wed Jul 14 12:36:32 1999
--- Completion/User/_rlogin	Wed Jul 14 12:37:42 1999
***************
*** 1,7 ****
  #compdef rlogin rsh ssh
  
  if [[ CURRENT -eq 2 ]]; then
!   compgen -k hosts
  elif [[ CURRENT -eq 3 ]]; then
    compadd - -l
  else
--- 1,7 ----
  #compdef rlogin rsh ssh
  
  if [[ CURRENT -eq 2 ]]; then
!   _hosts
  elif [[ CURRENT -eq 3 ]]; then
    compadd - -l
  else
*** Completion/User/_x_options.old	Wed Jul 14 12:36:39 1999
--- Completion/User/_x_options	Wed Jul 14 12:37:42 1999
***************
*** 3,9 ****
  # A simple pattern completion, just as an example.
  
  if [ "$words[CURRENT-1]" = "-display" ]; then
!   compgen -k hosts -S':0'
  else
!   compadd -J options - -display -name -xrm
  fi
--- 3,9 ----
  # A simple pattern completion, just as an example.
  
  if [ "$words[CURRENT-1]" = "-display" ]; then
!   ISUFFIX=':0' _hosts
  else
!   compadd -P- -J options - display name xrm
  fi


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1999-07-26  0:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-07-14 12:46 PATCH: Re: Completion/User functions again Sven Wischnowsky
1999-07-14 13:12 ` Tanaka Akira
1999-07-20 18:05   ` CVS completer (Re: PATCH: Re: Completion/User functions again) Bart Schaefer
1999-07-26  0:52     ` Tanaka Akira
1999-07-14 14:29 ` Completion/User functions again Oliver Kiddle
  -- strict thread matches above, loose matches on Subject: below --
1999-07-14 10:37 Andrej Borsenkow
1999-07-14 12:09 ` PATCH: " Oliver Kiddle

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).