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

compctl examples



The following patch improves some of the example compctls in the
distribution, and adds a completion for gcc (mostly lots of option
names).

-zefram

Index: Misc/compctl-examples
***************
*** 12,38 ****
  #
  #-------------------------------------------------------------------------------
  # Completion for zsh builtins.
! compctl -j -P '%' fg bg wait jobs disown
  compctl -A shift
  compctl -caF type whence which
! compctl -F unfunction
  compctl -a unalias
! compctl -v export integer typeset declare readonly unset vared
  compctl -e disable
  compctl -d enable
! compctl -k '(cputime filesize datasize stacksize coredumpsize resident \
!    memoryuse memorylocked descriptors openfiles vmemorysize)' limit ulimit
  compctl -l '' -x 'p[1]' -f -- . source
  compctl -s '`unsetopt`' setopt
  compctl -s '`setopt`' unsetopt
  
  # Anything after nohup is a command by itself with its own completion
! compctl -l '' nohup exec nice eval
  compctl -x 'p[1]' -c - 'p[2,-1]' -k signals -- trap
  compctl -l '' -x 'p[1]' -B -- builtin
  #-------------------------------------------------------------------------------
  # kill takes signal names as the first argument after -, but job names after %
! compctl -j -P % -x 's[-] p[1]' -k signals -- kill
  #-------------------------------------------------------------------------------
  compctl -s '$(groups)' newgrp
  compctl -f -x 'p[1]' -s '$(groups)' -- chgrp
--- 12,50 ----
  #
  #-------------------------------------------------------------------------------
  # Completion for zsh builtins.
! compctl -z -P '%' bg
! compctl -j -P '%' fg jobs disown
! compctl -j -P '%' + -s '`ps -x | tail +2 | cut -c1-5`' wait
  compctl -A shift
  compctl -caF type whence which
! compctl -c unhash
! compctl -x 'w[1,-d] p[2]' -n - 'w[1,-d] p[3]' -g '*(-/)' - \
! 	'p[1]' -c - 'p[2]' -g '*(-x)' -- hash
! compctl -F functions unfunction
  compctl -a unalias
! compctl -v getln getopts read unset vared
! compctl -v -S '=' -q declare export integer local readonly typeset
  compctl -e disable
  compctl -d enable
! compctl -k "(`limit | cut -d' ' -f1`)" limit ulimit
  compctl -l '' -x 'p[1]' -f -- . source
  compctl -s '`unsetopt`' setopt
  compctl -s '`setopt`' unsetopt
+ compctl -b bindkey
+ compctl -c -x 'C[-1,-*k]' -A - 'C[-1,-*K]' -F -- compctl
+ compctl -x 'C[-1,-*e]' -c - 'C[-1,-[ARWI]##]' -f -- fc
+ compctl -x 'p[1]' - 'p[2,-1]' -l '' -- sched
+ compctl -x 'C[-1,[+-]o]' -o - 'c[-1,-A]' -A -- set
  
  # Anything after nohup is a command by itself with its own completion
! compctl -l '' nohup exec nice eval - time rusage
  compctl -x 'p[1]' -c - 'p[2,-1]' -k signals -- trap
  compctl -l '' -x 'p[1]' -B -- builtin
  #-------------------------------------------------------------------------------
  # kill takes signal names as the first argument after -, but job names after %
! # or PIDs as a last resort
! compctl -j -P '%' + -s '`ps -x | tail +2 | cut -c1-5`' + \
! 	-x 's[-] p[1]' -k "($signals[1,-3])" -- kill
  #-------------------------------------------------------------------------------
  compctl -s '$(groups)' newgrp
  compctl -f -x 'p[1]' -s '$(groups)' -- chgrp
***************
*** 42,48 ****
     's[-f],c[-1,-f]' -f -- mail elm
  #-------------------------------------------------------------------------------
  compctl -g "*.[cCoa]" -x 's[-I]' -g "*(/)" - \
!    's[-l]' -s '${(s.:.)LD_LIBRARY_PATH}/lib*.a(:t:r:s/lib//)' -- cc gcc
  compctl -s "\$(awk '/^[a-zA-Z0-9][^ 	]+:/ {print \$1}' FS=: [mM]akefile)" -x \
     'c[-1,-f]' -f -- make gmake
  compctl -f -x 'C[-1,*f*] p[2]' -g "*.tar" -- tar
--- 54,60 ----
     's[-f],c[-1,-f]' -f -- mail elm
  #-------------------------------------------------------------------------------
  compctl -g "*.[cCoa]" -x 's[-I]' -g "*(/)" - \
!    's[-l]' -s '${(s.:.)^LD_LIBRARY_PATH}/lib*.a(:t:r:s/lib//)' -- cc
  compctl -s "\$(awk '/^[a-zA-Z0-9][^ 	]+:/ {print \$1}' FS=: [mM]akefile)" -x \
     'c[-1,-f]' -f -- make gmake
  compctl -f -x 'C[-1,*f*] p[2]' -g "*.tar" -- tar
***************
*** 51,57 ****
  compctl -g '*(/)' rmdir dircmp
  #-------------------------------------------------------------------------------
  # Cd/pushd only directories or symbolic links to directories
! compctl -g '*(-/) cd pushd
  
  # Another possibility for cd/pushd is to use it in conjunction with the
  # cdmatch function (in the Functions subdirectory of zsh distribution).
--- 63,69 ----
  compctl -g '*(/)' rmdir dircmp
  #-------------------------------------------------------------------------------
  # Cd/pushd only directories or symbolic links to directories
! compctl -g '*(-/)' cd pushd
  
  # Another possibility for cd/pushd is to use it in conjunction with the
  # cdmatch function (in the Functions subdirectory of zsh distribution).
***************
*** 64,69 ****
--- 76,87 ----
  
  # rlogin takes hosts and users after `-l'
  compctl -k hosts -x 'c[-1,-l]' -u -- rlogin
+ 
+ # rcp: match files *and* hosts initially, match files after a :, if the first
+ # argument contained a : then the second matches files and vice versa.
+ compctl -f -k hosts -x 'n[1,:]' -f - \
+ 	'p[1] W[2,*:*]' -f - 'p[1]' -k hosts -S ':' - \
+ 	'p[2] W[1,*:*]' -f - 'p[2]' -k hosts -S ':' -- rcp
  #-------------------------------------------------------------------------------
  # Strip, profile, and debug only executables.  The compctls for the
  # debuggers could be better, of course.
***************
*** 296,298 ****
--- 314,335 ----
      [[ $ngtrue = 1 ]] || unsetopt nullglob
  }
  
+ #-------------------------------------------------------------------------------
+ # GCC completion, by Andrew Main
+ # completes to filenames (*.c, *.C, *.o, etc.); to miscellaneous options after
+ # a -; to various -f options after -f (and similarly -W, -g and -m); and to a
+ # couple of other things at different points.
+ # The -l completion is nicked from the cc compctl above.
+ # The -m completion should be tailored to each system; the one below is i386.
+ compctl -g '*.([cCmisSoa]|cc|cxx|ii)' -x \
+ 	's[-l]' -s '${(s.:.)^LD_LIBRARY_PATH}/lib*.a(:t:r:s/lib//)' - \
+ 	'c[-1,-x]' -k '(none c objective-c c-header c++ cpp-output assembler assembler-with-cpp)' - \
+ 	'c[-1,-o]' -f - \
+ 	'C[-1,-i(nclude|macros)]' -g '*.h' - \
+ 	'C[-1,-i(dirafter|prefix)]' -g '*(-/)' - \
+ 	's[-B][-I][-L]' -g '*(-/)' - \
+ 	's[-fno-],s[-f]' -k '(all-virtual cond-mismatch dollars-in-identifiers enum-int-equiv external-templates asm builtin strict-prototype signed-bitfields signd-char this-is-variable unsigned-bitfields unsigned-char writable-strings syntax-only pretend-float caller-saves cse-follow-jumps cse-skip-blocks delayed-branch elide-constructors expensive-optimizations fast-math float-store force-addr force-mem inline-functions keep-inline-functions memoize-lookups default-inline defer-pop function-cse inline peephole omit-frame-pointer rerun-cse-after-loop schedule-insns schedule-insns2 strength-reduce thread-jumps unroll-all-loops unroll-loops)' - \
+ 	's[-g]' -k '(coff xcoff xcoff+ dwarf dwarf+ stabs stabs+ gdb)' - \
+ 	's[-mno-][-mno][-m]' -k '(486 soft-float fp-ret-in-387)' - \
+ 	's[-Wno-][-W]' -k '(all aggregate-return cast-align cast-qual char-subscript comment conversion enum-clash error format id-clash-6 implicit inline missing-prototypes missing-declarations nested-externs import parentheses pointer-arith redundant-decls return-type shadow strict-prototypes switch template-debugging traditional trigraphs uninitialized unused write-strings)' - \
+ 	's[-]' -k '(pipe ansi traditional traditional-cpp trigraphs pedantic pedantic-errors nostartfiles nostdlib static shared symbolic include imacros idirafter iprefix iwithprefix nostdinc nostdinc++ undef)' -X 'Use "-f", "-g", "-m" or "-W" for more options' -- gcc g++



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