home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Shells / zsh-3.0.5-MIHS / src / Misc / compctl-examples < prev    next >
Encoding:
Text File  |  1997-06-03  |  23.2 KB  |  525 lines

  1. # $Id: compctl-examples,v 2.12 1996/08/14 17:01:36 hzoli Exp $
  2. #
  3. # This file gives examples of possible programmable completions (compctl).
  4. # You can either put the compctl commands in your .zshrc file, or put them
  5. # in a separate file (say .zcompctl) and source it from your .zshrc file.
  6. #
  7. # These are just examples. Use and modify to personal taste.  Copying
  8. # this file without thought will needlessly increase zsh's memory usage
  9. # and startup time.
  10. #
  11. # For a detailed description of how these work, check the zshcompctl man
  12. # page.
  13. #
  14. #------------------------------------------------------------------------------
  15. hosts=("${(s: :)${(s:    :)${${(f)$(</etc/hosts)}%%\#*}#*[     ]*}}")
  16.  
  17. # groups=( $(cut -d: -f1 /etc/group) )
  18. # groups=( $(ypcat group.byname | cut -d: -f1) ) # if you use NIS
  19.  
  20. # It can be done without forking, but it used too much memory in old zsh's:
  21. groups=( "${${(f)$(</etc/group)}%%:*}" )
  22. #groups=( "${${(f)$(ypcat groups)}%%:*}" ) # if you use NIS
  23.  
  24. # Completion for zsh builtins.
  25. compctl -z -P '%' bg
  26. compctl -j -P '%' fg jobs disown
  27. compctl -j -P '%' + -s '`ps -x | tail +2 | cut -c1-5`' wait
  28. compctl -A shift
  29. compctl -c type whence where which
  30. compctl -m -x 'W[1,-*d*]' -n - 'W[1,-*a*]' -a - 'W[1,-*f*]' -F -- unhash
  31. compctl -m -q -S '=' -x 'W[1,-*d*] n[1,=]' -g '*(-/)' - \
  32.     'W[1,-*d*]' -n -q -S '=' - 'n[1,=]' -g '*(*)' -- hash
  33. compctl -F functions unfunction
  34. compctl -k '(al dc dl do le up al bl cd ce cl cr
  35.     dc dl do ho is le ma nd nl se so up)' echotc
  36. compctl -a unalias
  37. compctl -v getln getopts read unset vared
  38. compctl -v -S '=' -q declare export integer local readonly typeset
  39. compctl -eB -x 'p[1] s[-]' -k '(a f m r)' - \
  40.     'C[1,-*a*]' -ea - 'C[1,-*f*]' -eF - 'C[-1,-*r*]' -ew -- disable
  41. compctl -dB -x 'p[1] s[-]' -k '(a f m r)' - \
  42.     'C[1,-*a*]' -da - 'C[1,-*f*]' -dF - 'C[-1,-*r*]' -dw -- enable
  43. compctl -k "(${(j: :)${(f)$(limit)}%% *})" limit unlimit
  44. compctl -l '' -x 'p[1]' -f -- . source
  45. # Redirection below makes zsh silent when completing unsetopt xtrace
  46. compctl -s '$(setopt 2>/dev/null)' + -o + -x 's[no]' -o -- unsetopt
  47. compctl -s '$(unsetopt)' + -o + -x 's[no]' -o -- setopt
  48. compctl -s '${^fpath}/*(N:t)' autoload
  49. compctl -b bindkey
  50. compctl -c -x 'C[-1,-*k]' -A - 'C[-1,-*K]' -F -- compctl
  51. compctl -x 'C[-1,-*e]' -c - 'C[-1,-[ARWI]##]' -f -- fc
  52. compctl -x 'p[1]' - 'p[2,-1]' -l '' -- sched
  53. compctl -x 'C[-1,[+-]o]' -o - 'c[-1,-A]' -A -- set
  54.  
  55. # Anything after nohup is a command by itself with its own completion
  56. compctl -l '' nohup noglob exec nice eval - time rusage
  57. compctl -l '' -x 'p[1]' -eB -- builtin
  58. compctl -l '' -x 'p[1]' -em -- command
  59. compctl -x 'p[1]' -c - 'p[2,-1]' -k signals -- trap
  60. #------------------------------------------------------------------------------
  61. # kill takes signal names as the first argument after -, but job names after %
  62. # or PIDs as a last resort
  63. compctl -j -P '%' + -s '`ps -x | tail +2 | cut -c1-5`' + \
  64.     -x 's[-] p[1]' -k "($signals[1,-3])" -- kill
  65. #------------------------------------------------------------------------------
  66. compctl -s '$(groups)' + -k groups newgrp
  67. compctl -f -x 'p[1], p[2] C[-1,-*]' -k groups -- chgrp
  68. compctl -f -x 'p[1] n[-1,.], p[2] C[-1,-*] n[-1,.]' -k groups - \
  69.     'p[1], p[2] C[-1,-*]' -u -S '.' -q -- chown
  70. compctl -g '*.x' + -g '*(-/)' rpcgen
  71. compctl -u -x 's[+] c[-1,-f],s[-f+]' -g '~/Mail/*(:t)' - \
  72.     's[-f],c[-1,-f]' -f -- mail elm
  73. #------------------------------------------------------------------------------
  74. compctl -s "\$(awk '/^[a-zA-Z0-9][^     ]+:/ {print \$1}' FS=: [mM]akefile)" -x \
  75.     'c[-1,-f]' -f -- make gmake pmake
  76. compctl -f -x 'W[1,*(z*f|f*z)*] p[2]' -g '*.(tar.gz|tgz|tar.Z|taz)' - \
  77.     'W[1,*f*] p[2]' -g '*.tar' -- gnutar gtar tar
  78. #------------------------------------------------------------------------------
  79. # rmdir only real directories
  80. compctl -g '*(/)' rmdir dircmp
  81. #------------------------------------------------------------------------------
  82. # cd/pushd only directories or symbolic links to directories
  83. compctl -g '*(-/)' cd chdir dirs pushd
  84.  
  85. # Another possibility for cd/pushd is to use it in conjunction with the
  86. # cdmatch function (in the Functions subdirectory of zsh distribution).
  87. compctl -K cdmatch -S '/' -q -x 'p[2]' -Q -K cdmatch2 - \
  88.     'S[/][~][./][../]' -g '*(-/)' + -g '*(-/D)' - \
  89.     'n[-1,/]' -K cdmatch -S '/' -q -- cd chdir pushd
  90. #------------------------------------------------------------------------------
  91. # If the command is rsh, make the first argument complete to hosts and treat the
  92. # rest of the line as a command on its own.
  93. compctl -k hosts -x 'p[2,-1]' -l '' -- rsh
  94.  
  95. # rlogin takes hosts and users after `-l'
  96. compctl -k hosts -x 'c[-1,-l]' -u -- rlogin
  97.  
  98. # rcp: match users, hosts and files initially.  Match files after a :, or hosts
  99. # after an @.  If one argument contains a : then the other matches files only.
  100. # Not quite perfect; compctl just isn't up to it yet.
  101. compctl -u -k hosts -f -x 'n[1,:]' -f - 'n[1,@]' -k hosts -S ':' - \
  102.     'p[1] W[2,*:*]' -f - 'p[1] W[2,*?*]' -u -k hosts -S ':' - \
  103.     'p[2] W[1,*:*]' -f - 'p[2] W[1,*?*]' -u -k hosts -S ':' -- rcp
  104.  
  105. compctl -k hosts host nslookup rup rusers
  106. #------------------------------------------------------------------------------
  107. # strip, profile, and debug only executables.  The compctls for the
  108. # debuggers could be better, of course.
  109. compctl -g '*(*)' strip gprof adb dbx xdbx ups
  110. compctl -g '*.[ao]' -g '*(*)' nm
  111. #------------------------------------------------------------------------------
  112. # shells: compctl needs some more enhancement to do -c properly.
  113. compctl -f -x 'C[-1,-*c]' -c - 'C[-1,[-+]*o]' -o -- bash ksh sh zsh
  114. #------------------------------------------------------------------------------
  115. # su takes a username and args for the shell.
  116. compctl -u -x 'w[1,-]p[3,-1]' -l sh - 'w[1,-]' -u - 'p[2,-1]' -l sh -- su
  117. #------------------------------------------------------------------------------
  118. # Run ghostscript on postscript files, but if no postscript file matches what
  119. # we already typed, complete directories as the postscript file may not be in
  120. # the current directory.
  121. compctl -g '*.(e|E|)(ps|PS)' + -g '*(-/)' \
  122.     gs ghostview nup psps pstops psmulti psnup psselect
  123. #------------------------------------------------------------------------------
  124. # Similar things for tex, texinfo and dvi files.
  125. compctl -g '*.tex*' + -g '*(-/)' {,la,gla,ams{la,},{g,}sli}tex texi2dvi
  126. compctl -g '*.dvi' + -g '*(-/)' xdvi dvips
  127. #------------------------------------------------------------------------------
  128. # For rcs users, co and rlog from the RCS directory.  We don't want to see
  129. # the RCS and ,v though.
  130. compctl -g 'RCS/*(:s@RCS/@@:s/,v//)' co rlog rcs rcsdiff
  131. #------------------------------------------------------------------------------
  132. # gzip uncompressed files, but gzip -d only gzipped or compressed files
  133. compctl -x 'R[-*[dt],^*]' -g '*.(gz|z|Z|t[agp]z|tarZ|tz)' + -g '*(-/)' + -f - \
  134.     's[]' -g '^*(.(tz|gz|t[agp]z|tarZ|zip|ZIP|jpg|JPG|gif|GIF|[zZ])|[~#])' \
  135.     + -f -- gzip
  136. compctl -g '*.(gz|z|Z|t[agp]z|tarZ|tz)' + -g '*(-/)' gunzip gzcat zcat
  137. compctl -g '*.Z' + -g '*(-/)' uncompress zmore
  138. compctl -g '*.F' + -g '*(-/)' melt fcat
  139. #------------------------------------------------------------------------------
  140. # ftp takes hostnames
  141. ftphosts=(prep.ai.mit.edu wuarchive.wustl.edu ftp.uu.net ftp.math.gatech.edu)
  142. compctl -k ftphosts ftp
  143.  
  144. # Some systems have directories containing indices of ftp servers.
  145. # For example: we have the directory /home/ftp/index/INDEX containing
  146. # files of the form `<name>-INDEX.Z', this leads to:
  147. #compctl -g '/home/ftp/index/INDEX/*-INDEX.Z(:t:r:s/-INDEX//)' ftp tftp
  148. #------------------------------------------------------------------------------
  149. # Change default completion (see the multicomp function in the Function
  150. # subdirectory of the zsh distribution).
  151. #compctl -D -f + -U -K multicomp
  152. # If completion of usernames is slow for you, you may want to add something
  153. # like
  154. #    -x 'C[0,*/*]' -f - 's[~]' -S/ -k users + -u
  155. # where `users' contains the names of the users you want to complete often.
  156. # If you want to use this and to be able to complete named directories after
  157. # the `~' you should add `+ -n' at the end
  158. #------------------------------------------------------------------------------
  159. # This is to complete all directories under /home, even those that are not
  160. # yet mounted (if you use the automounter).
  161.  
  162. # This is for NIS+ (e.g. Solaris 2.x)
  163. #compctl -Tx 's[/home/] C[0,^/home/*/*]'  -S '/' -s '$(niscat auto_home.org_dir | \
  164. #    awk '\''/export\/[a-zA-Z]*$/ {print $NF}'\'' FS=/)'
  165.  
  166. # And this is for YP (e.g. SunOS4.x)
  167. #compctl -Tx 's[/home/] C[0,^/home/*/*]' -S '/' -s '$(ypcat auto.home | \
  168. #    awk '\''/export\/[a-zA-Z]*$/ {print $NF}'\'' FS=/)'
  169. #------------------------------------------------------------------------------
  170. # Find is very system dependent, this one is for GNU find.
  171. # Note that 'r[-exec,;]' must come first
  172. if [[ -r /proc/filesystems ]]; then
  173.     # Linux
  174.     filesystems='"${${(f)$(</proc/filesystems)}#*    }"'
  175. else
  176.     filesystems='ufs 4.2 4.3 nfs tmp mfs S51K S52K'
  177. fi
  178. compctl -x 'r[-exec,;][-ok,;]' -l '' - \
  179. 's[-]' -s 'daystart {max,min,}depth follow noleaf version xdev
  180.     {a,c,}newer {a,c,m}{min,time} empty false {fs,x,}type gid inum links
  181.     {i,}{l,}name {no,}{user,group} path perm regex size true uid used
  182.     exec {f,}print{f,0,} ok prune ls' - \
  183.     'p[1]' -g '. .. *(-/)' - \
  184.     'C[-1,-((a|c|)newer|fprint(|0|f))]' -f - \
  185.     'c[-1,-fstype]' -s $filesystems - \
  186.     'c[-1,-group]' -k groups - \
  187.     'c[-1,-user]' -u -- find
  188. #------------------------------------------------------------------------------
  189. # Generic completion for C compiler.
  190. compctl -g "*.[cCoa]" -x 's[-I]' -g "*(/)" - \
  191.     's[-l]' -s '${(s.:.)^LD_LIBRARY_PATH}/lib*.a(:t:r:s/lib//)' -- cc
  192. #------------------------------------------------------------------------------
  193. # GCC completion, by Andrew Main
  194. # completes to filenames (*.c, *.C, *.o, etc.); to miscellaneous options after
  195. # a -; to various -f options after -f (and similarly -W, -g and -m); and to a
  196. # couple of other things at different points.
  197. # The -l completion is nicked from the cc compctl above.
  198. # The -m completion should be tailored to each system; the one below is i386.
  199. compctl -g '*.([cCmisSoak]|cc|cxx|ii|k[ih])' -x \
  200.     's[-l]' -s '${(s.:.)^LD_LIBRARY_PATH}/lib*.a(:t:r:s/lib//)' - \
  201.     'c[-1,-x]' -k '(none c objective-c c-header c++ cpp-output
  202.     assembler assembler-with-cpp)' - \
  203.     'c[-1,-o]' -f - \
  204.     'C[-1,-i(nclude|macros)]' -g '*.h' - \
  205.     'C[-1,-i(dirafter|prefix)]' -g '*(-/)' - \
  206.     's[-B][-I][-L]' -g '*(-/)' - \
  207.     's[-fno-],s[-f]' -k '(all-virtual cond-mismatch dollars-in-identifiers
  208.     enum-int-equiv external-templates asm builtin strict-prototype
  209.     signed-bitfields signd-char this-is-variable unsigned-bitfields
  210.     unsigned-char writable-strings syntax-only pretend-float caller-saves
  211.     cse-follow-jumps cse-skip-blocks delayed-branch elide-constructors
  212.     expensive-optimizations fast-math float-store force-addr force-mem
  213.     inline-functions keep-inline-functions memoize-lookups default-inline
  214.     defer-pop function-cse inline peephole omit-frame-pointer
  215.     rerun-cse-after-loop schedule-insns schedule-insns2 strength-reduce
  216.     thread-jumps unroll-all-loops unroll-loops)' - \
  217.     's[-g]' -k '(coff xcoff xcoff+ dwarf dwarf+ stabs stabs+ gdb)' - \
  218.     's[-mno-][-mno][-m]' -k '(486 soft-float fp-ret-in-387)' - \
  219.     's[-Wno-][-W]' -k '(all aggregate-return cast-align cast-qual
  220.     char-subscript comment conversion enum-clash error format id-clash-6
  221.     implicit inline missing-prototypes missing-declarations nested-externs
  222.     import parentheses pointer-arith redundant-decls return-type shadow
  223.     strict-prototypes switch template-debugging traditional trigraphs
  224.     uninitialized unused write-strings)' - \
  225.     's[-]' -k '(pipe ansi traditional traditional-cpp trigraphs pedantic
  226.     pedantic-errors nostartfiles nostdlib static shared symbolic include
  227.     imacros idirafter iprefix iwithprefix nostdinc nostdinc++ undef)' \
  228.     -X 'Use "-f", "-g", "-m" or "-W" for more options' -- gcc g++
  229. #------------------------------------------------------------------------------
  230. # There are (at least) two ways to complete manual pages.  This one is
  231. # extremely memory expensive if you have lots of man pages
  232. man_var() {
  233.     man_pages=( ${^manpath}/man*/*(N:t:r) )
  234.     compctl -k man_pages -x 'C[-1,-P]' -m - \
  235.         'R[-*l*,;]' -g '*.(man|[0-9nlpo](|[a-z]))' + -g '*(-/)' -- man
  236.     reply=( $man_pages )
  237. }
  238. compctl -K man_var -x 'C[-1,-P]' -m - \
  239.     'R[-*l*,;]' -g '*.(man|[0-9nlpo](|[a-z]))' + -g '*(-/)' -- man
  240.  
  241. # This one isn't that expensive but somewhat slower
  242. man_glob () {
  243.    local a
  244.    read -cA a
  245.    if [[ $a[2] = -s ]] then         # Or [[ $a[2] = [0-9]* ]] for BSD
  246.      reply=( ${^manpath}/man$a[3]/$1*$2(N:t:r) )
  247.    else
  248.      reply=( ${^manpath}/man*/$1*$2(N:t:r) )
  249.    fi
  250. }
  251. #compctl -K man_glob -x 'C[-1,-P]' -m - \
  252. #    'R[-*l*,;]' -g '*.(man|[0-9nlpo](|[a-z]))' + -g '*(-/)' -- man
  253. #------------------------------------------------------------------------------
  254. # xsetroot: gets possible colours, cursors and bitmaps from wherever.
  255. # Uses two auxiliary functions.  You might need to change the path names.
  256. # The =:- can be omitted if you use a beta6-hzoli4 or later version.
  257. Xcolours() {
  258.   reply=( ${(L)=:-$(awk '{ if (NF = 4) print $4 }' \
  259.     < /usr/openwin/lib/X11/rgb.txt)} )
  260. }
  261. Xcursor() {
  262.   reply=( $(sed -n 's/^#define[     ][     ]*XC_\([^     ]*\)[     ].*$/\1/p' \
  263.       < /usr/include/X11/cursorfont.h) )
  264. }
  265. compctl -k '(-help -def -display -cursor -cursor_name -bitmap -mod -fg -bg
  266.     -grey -rv -solid -name)' -x \
  267.     'c[-1,-display]' -s '$DISPLAY' -k hosts -S ':0' - \
  268.     'c[-1,-cursor]' -f -  'c[-2,-cursor]' -f - \
  269.     'c[-1,-bitmap]' -g '/usr/include/X11/bitmaps/*' - \
  270.     'c[-1,-cursor_name]' -K Xcursor - \
  271.     'C[-1,-(solid|fg|bg)]' -K Xcolours -- xsetroot
  272. #------------------------------------------------------------------------------
  273. # dd
  274. compctl -k '(if of conv ibs obs bs cbs files skip file seek count)' \
  275.     -S '=' -x 's[if=], s[of=]' -f - 'C[0,conv=*,*] n[-1,,], s[conv=]' \
  276.     -k '(ascii ebcdic ibm block unblock lcase ucase swap noerror sync)' \
  277.     -q -S ',' - 'n[-1,=]' -X '<number>'  -- dd
  278. #------------------------------------------------------------------------------
  279. # Various MH completions by Peter Stephenson
  280. # You may need to edit where it says *Edit Me*.
  281.  
  282. # The following three functions are best autoloaded.
  283. # mhcomp completes folders (including subfolders),
  284. # mhfseq completes sequence names and message numbers,
  285. # mhfile completes files in standard MH locations.
  286.  
  287. function mhcomp {
  288.   # Completion function for MH folders.
  289.   # Works with both + (rel. to top) and @ (rel. to current).
  290.   local nword args pref char mhpath
  291.   read -nc nword
  292.   read -cA args
  293.  
  294.   pref=$args[$nword]
  295.   char=$pref[1]
  296.   pref=$pref[2,-1]
  297.  
  298.   # The $(...) here accounts for most of the time spent in this function.
  299.   if [[ $char = + ]]; then
  300.   #    mhpath=$(mhpath +)
  301.   # *Edit Me*: use a hard wired value here: it's faster.
  302.     mhpath=~/Mail
  303.   elif [[ $char = @ ]]; then
  304.     mhpath=$(mhpath)
  305.   fi
  306.  
  307.   eval "reply=($mhpath/$pref*(N-/))"
  308.  
  309.   # I'm frankly amazed that this next step works, but it does.
  310.   reply=(${reply#$mhpath/})
  311. }
  312.  
  313. mhfseq() {
  314.   # Extract MH message names and numbers for completion.  Use of the
  315.   # correct folder, if it is not the current one, requires that it
  316.   # should be the previous command line argument.  If the previous
  317.   # argument is `-draftmessage', a hard wired draft folder name is used.
  318.  
  319.   local folder foldpath words pos nums
  320.   read -cA words
  321.   read -cn pos
  322.  
  323.   # Look for a folder name.
  324.   # First try the previous word.
  325.   if [[ $words[$pos-1] = [@+]* ]]; then
  326.     folder=$words[$pos-1]
  327.   # Next look and see if we're looking for a draftmessage
  328.   elif [[ $words[$pos-1] = -draftmessage ]]; then
  329.     # *Edit Me*:  shortcut -- hard-wire draftfolder here
  330.     # Should really look for a +draftfolder argument.
  331.     folder=+drafts
  332.   fi
  333.   # Else use the current folder ($folder empty)
  334.  
  335.   if [[ $folder = +* ]]; then
  336.   # *Edit Me*:  use hard-wired path with + for speed.
  337.     foldpath=~/Mail/$folder[2,-1]
  338.   else
  339.     foldpath=$(mhpath $folder)
  340.   fi
  341.  
  342.   # Extract all existing message numbers from the folder.
  343.   nums=($foldpath/<->(N:t))
  344.   # If that worked, look for marked sequences.
  345.   # *Edit Me*: if you never use non-standard sequences, comment out
  346.   # or delete the next three lines.
  347.   if (( $#nums )); then
  348.     nums=($nums $(mark $folder | awk -F: '{print $1}'))
  349.   fi
  350.  
  351.   # *Edit Me*:  `unseen' is the value of Unseen-Sequence, if it exists;
  352.   set -A reply next cur prev first last all unseen $nums
  353.  
  354. }
  355.  
  356. mhfile () {
  357.   # Find an MH file; for use with -form arguments and the like.
  358.   # Use with compctl -K mhfile.
  359.  
  360.   local mhfpath file
  361.   # *Edit Me*:  Array containing all the places MH will look for templates etc.
  362.   mhfpath=(~/Mail /usr/local/lib/MH)
  363.  
  364.   # Emulate completeinword behaviour as appropriate
  365.   local wordstr
  366.   if [[ -o completeinword ]]; then
  367.     wordstr='$1*$2'
  368.   else
  369.     wordstr='$1$2*'
  370.   fi
  371.  
  372.   if [[ $1$2 = */* ]]; then
  373.     # path given: don't search MH locations
  374.     eval "reply=($wordstr(.N))"
  375.   else
  376.     # no path:  only search MH locations.
  377.     eval "reply=(\$mhfpath/$wordstr(.N:t))"
  378.   fi
  379. }
  380.  
  381. # Note: you must type the initial + or @ of a folder name to get
  382. # completion, even in places where only folder names are allowed.
  383. # Abbreviations for options are not recognised.  Hit tab to complete
  384. # the option name first.
  385. compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
  386.   's[-]' -k "(all fast nofast header noheader help list nolist \
  387.   pack nopack pop push recurse norecurse total nototal)" -- folder
  388. compctl -K mhfseq -x 's[+][@],c[-1,-draftfolder] s[+][@]' \
  389.   -K mhcomp -S / -q - 'c[-1,-draftmessage]' -K mhfseq - \
  390.   'C[-1,-(editor|whatnowproc)]' -c - \
  391.   's[-]' -k "(draftfolder draftmessage nodraftfolder editor noedit \
  392.   file form use nouse whatnowproc nowhatnowproc help)" - \
  393.   'c[-1,-form]' -K mhfile -- comp
  394. compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
  395.   's[-]' -k "(audit noaudit changecur nochangecur form format \
  396.   file silent nosilent truncate notruncate width help)" - \
  397.   'C[-1,-(audit|form)]' -K mhfile - 'c[-1,-file]' -f + -- inc
  398. compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
  399.   's[-]' -k "(sequence add delete list public nopublic zero nozero help)" -- \
  400.   mark
  401. compctl -K mhfseq -x 's[+][@]' \
  402.   -K mhcomp -S / -q - 'c[-1,-file]' -f - 'c[-1,-rmmprov]' -c - \
  403.   's[-]' -k "(draft link nolink preserve nopreserve src file \
  404.   rmmproc normmproc help)" -- refile
  405. compctl -K mhfseq -x 's[+][@]' \
  406.   -K mhcomp -S / -q - 'c[-1,-draftmessage]'  -K mhfseq -\
  407.   's[-]' -k "(annotate noannotate cc nocc draftfolder nodraftfolder \
  408.   draftmessage editor noedit fcc filter form inplace noinplace query \
  409.   noquery width whatnowproc nowhatnowproc help)" - 'c[-1,(cc|nocc)]' \
  410.   -k "(all to cc me)" - 'C[-1,-(filter|form)]' -K mhfile - \
  411.   'C[-1,-(editor|whatnowproc)]' -c -- repl
  412. compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
  413.   's[-]' -k "(clear noclear form format header noheader reverse noreverse \
  414.   file help width)" - 'c[-1,-file]' -f - 'c[-1,-form]' -K mhfile -- scan
  415. compctl -K mhfseq -x 's[+][@]'  -K mhcomp -S / -q - \
  416.   's[-]' -k "(draft form moreproc nomoreproc header noheader \
  417.    showproc noshowproc length width help)" - 'C[-1,-(show|more)proc]' -c - \
  418.    'c[-1,-file]' -f - 'c[-1,-form]' -K mhfile - \
  419.    'c[-1,-length]' -s '$LINES' - 'c[-1,-width]' -s '$COLUMNS' -- show next prev
  420. compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - 's[-]' \
  421.   -k "(help)" -- rmm
  422. compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
  423.   's[-]' -k "(after before cc date datefield from help list nolist \
  424.   public nopublic search sequence subject to zero nozero not or and \
  425.   lbrace rbrace)" -- pick
  426. compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - 's[-]' \
  427.   -k "(alias check draft draftfolder draftmessage help nocheck \
  428.   nodraftfolder)" -- whom
  429. compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - 's[-]' \
  430.   -k "(file part type list headers noheaders realsize norealsize nolist \
  431.   show serialonly noserialonly form pause nopause noshow store auto noauto \
  432.   nostore cache nocache rcache wcache check nocheck ebcdicsafe noebcdicsafe \
  433.   rfc934mode norfc934mode verbose noverbose help)" - \
  434.   'c[-1,-file]' -f - 'c[-1,-form]' -K mhfile - \
  435.   'C[-1,-[rw]cache]' -k '(public private never ask)' -- mhn
  436. compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - 's[-]' -k '(help)' -- mhpath
  437. #------------------------------------------------------------------------------
  438. # By Bart Schaefer
  439. # CVS -- there's almost no way to make this all-inclusive, but ...
  440. #
  441. cvsflags=(-H -Q -q -r -w -l -n -t -v -b -e -d)
  442. cvscmds=(add admin checkout commit diff history import export log rdiff
  443.         release remove status tag rtag update)
  444.  
  445. # diff assumes gnu rcs using gnu diff
  446. # log assumes gnu rcs
  447.  
  448. compctl -k "($cvscmds $cvsflags)" \
  449.     -x "c[-1,-D]" -k '(today yesterday 1\ week\ ago)' \
  450.     - "r[add,;][ad,;][new,;]" -k "(-k -m)" -f \
  451.     - "r[admin,;][adm,;][rcs,;]" -K cvstargets \
  452.     - "r[checkout,;][co,;][get,;]" -k "(-A -N -P -Q -c -f -l -n -p -q -s -r -D -d -k -j)" \
  453.     - "r[commit,;][ci,;][com,;]" -k "(-n -R -l -f -m -r)"  -K cvstargets \
  454.     - "r[diff,;][di,;][dif,;]" -k "(-l -D -r -c -u -b -w)" -K cvstargets \
  455.     - "r[history,;][hi,;][his,;] c[-1,-u]" -u \
  456.     - "r[history,;][hi,;][his,;]" \
  457.     -k "(-T -c -o -m -x -a -e -l -w -D -b -f -n -p -r -t -u)" \
  458.     -K cvstargets \
  459.     - "r[import,;][im,;][imp,;]" -k "(-Q -q -I -b -m)" -f \
  460.     - "r[export,;][ex,;][exp,;]" -k "(-N -Q -f -l -n -q -r -D -d)" -f \
  461.     - "r[rlog,;][log,;][lo,;]" -k "(-l -R -h -b -t -r -w)" -K cvstargets \
  462.     - 'r[rlog,;][log,;][lo,;] s[-w] n[-1,,],s[-w]' -u -S , -q \
  463.     - "r[rdiff,;][patch,;][pa,;]" -k "(-Q -f -l -c -u -s -t -D -r -V)" -K cvstargets \
  464.     - "r[release,;][re,;][rel,;]" -k "(-Q -d -q)" -f \
  465.     - "r[remove,;][rm,;][delete,;]" -k "(-l -R)" -K cvstargets \
  466.     - "r[status,;][st,;][stat,;]" -k "(-v -l -R)" -K cvstargets \
  467.     - "r[tag,;][ta,;][freeze,;]" -k "(-Q -l -R -q -d -b)" -K cvstargets \
  468.     - "r[rtag,;][rt,;][rfreeze,;]" -k "(-Q -a -f -l -R -n -q -d -b -r -D)" -f \
  469.     - "r[update,;][up,;][upd,;]" -k "(-A -P -Q -d -f -l -R -p -q -k -r -D -j -I)" \
  470.     -K cvstargets \
  471.     -- cvs
  472. unset cvsflags cvscmds
  473.  
  474. cvstargets() {
  475.     local nword args pref f
  476.     setopt localoptions nullglob
  477.     read -nc nword; read -Ac args
  478.     pref=$args[$nword]
  479.     if [[ -d $pref:h && ! -d $pref ]]
  480.     then
  481.     pref=$pref:h
  482.     elif [[ $pref != */* ]]
  483.     then
  484.     pref=
  485.     fi
  486.     [[ -n "$pref" && "$pref" != */ ]] && pref=$pref/
  487.     if [[ -f ${pref}CVS/Entries ]]
  488.     then
  489.     reply=( "${pref}${^${${(f@)$(<${pref}CVS/Entries)}#/}%%/*}"
  490.         ${pref}*/**/CVS(:h) )
  491.     else
  492.     reply=( ${pref}*/**/CVS(:h) )
  493.     fi
  494. }
  495. #------------------------------------------------------------------------------
  496. # RedHat Linux rpm utility
  497. #
  498. compctl -s '$(rpm -qa)' \
  499.     -x 's[--]' -s 'oldpackage percent replacefiles replacepkgs noscripts
  500.                root excludedocs includedocs test upgrade test clean
  501.                short-circuit sign recompile rebuild resign querytags
  502.                queryformat version help quiet rcfile force hash' - \
  503.     's[ftp:]' -P '//' -s '$(</u/zsh/ftphosts)' -S '/' - \
  504.     'c[-1,--root]' -g '*(-/)' - \
  505.     'c[-1,--rcfile]' -f - \
  506.     'p[1] s[-b]' -k '(p l c i b a)' - \
  507.     'c[-1,--queryformat] N[-1,{]' \
  508.         -s '"${${(f)$(rpm --querytags)}#RPMTAG_}"' -S '}' - \
  509.     'W[1,-q*] C[-1,-([^-]*|)f*]' -f - \
  510.     'W[1,-i*], W[1,-q*] C[-1,-([^-]*|)p*]' \
  511.         -g '*.rpm' + -g '*(-/)' + -f -- rpm
  512. #------------------------------------------------------------------------------
  513. compctl -u -x 'c[-1,-w]' -f -- ac
  514. compctl -g '*.m(D.)' + -g '*(D-/)' mira
  515. #------------------------------------------------------------------------------
  516. # talk completion: complete local users, or users at hosts listed via rwho
  517. compctl -K talkmatch talk ytalk ytalk3
  518. function talkmatch {
  519.     local u
  520.     reply=($(users))
  521.     for u in "${${(f)$(rwho 2>/dev/null)}%%:*}"; do
  522.     reply=($reply ${u%% *}@${u##* })
  523.     done
  524. }
  525.