Newer
Older
sys.etc-skel / .zshcompctl
@HIROSE Yuuji HIROSE Yuuji on 12 Aug 2021 16 KB Add basic files
# This file gives some examples of compctl commands.
# You can either put the compctl commands in your .zshrc
# or include a separate file from your .zshrc with the
# source command.

###
# complete database
###
# All completions for zsh.

if [ -f ~/.rhosts ]; then                 
	hostnames=(`awk '{print $1}' ~/.rhosts` )
else
	hosnames=(localhost)
fi

if [ -f ~/.netrc ]; then
        ftpsites=( `grep '^machine' ~/.netrc | awk '{print $2}'` \
                        $hosts )
else    
        ftpsites=($hosts)
fi

# These are just examples, use and modify to personal taste.  Copying this
# file without thought will needlessly increase zsh's memory usage and
# startup time.

# For an explanation of what all this means, read either the
# introduction for some explanation or the manual for a detailed
# description.

# Strip, profile, and debug only executables.  The compctls for the
# debuggers could be better, of course.
compctl -g '*(x-)' strip gprof adb dbx xdbx ups

# See the func/cdmatch function in the distribution
autoload cdmatch
#compctl -K cdmatch -S '/' -x 'S[/][~]' -g '*(-/)' -- cd pushd
#compctl -g "*(/)" -S / -x 'S[/][~]' -g '*(-/)' --  cd pushd chdir pu
compctl -g "(|.)*(-/)" cd pushd chdir pu apath

# For rcs users, co and rlog from the RCS directory.  We don't want to see
# the RCS and ,v though.
compctl -g 'RCS/*(:t:s/\,v//)' co rlog rcs

# Anything after nohup is a command by itself with its own completion
# (the one for the trap builtin isn't perfect -- it does not complete
# signal names)
compctl -l '' nohup exec nice eval trap time fep sudo
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

# gzip files, but gzip -d only gzipped or compressed files
compctl -f -x 'R[-*d,^*]' -g '(|.)*.(gz|z|Z) (|.)*(-/)' + -g '(|.)*(-/)' -- gzip
compctl -g '*.gz *.z *.Z' + -g '(|.)*(-/)' gunzip   # zcat if you use GNU
compctl -g '*.Z' + -g '(|.)*(-/)' uncompress zmore  # zcat if you don't use GNU
## compctl -g '*.F' + -g '(|.)*(-/)' melt fcat

## # find is very system dependend, this one is for GNU find.
## compctl -x 's[-]' -k "(daystart depth follow maxdepth mindepth noleaf version xdev \
## amin anewer cmin cnewer ctime empty false fstype gid group inum links lname mmin \
## mtime name newer nouser nogroup path perm regex size true type uid used user xtype \
## exec fprint fprint0 fprintf ok print print0 printf prune ls)" - \
## 'p[1]' -g '. .. *(-/)' - \
## 'c[-1,-anewer][-1,-cnewer][-1,-newer][-1,-fprint][-1,fprint0][-1,fprintf]' -f - \
## 'c[-1,-fstype]' -k '(ufs 4.2 4.3 nfs tmp mfs S51K S52K)' - \
## 'c[-1,-group]' -s '$(groups)' - \
## 'c[-1,-user]' -u - \
## 'r[-exec,;][-ok,;]' -l '' -- find

# xsetroot: gets possible colours, cursors and bitmaps from wherever.
# Uses two auxiliary functions.  You might need to change the path names.
## Xcolours() { reply=($(awk '{ print $4 }' < /usr/lib/X11/X11/rgb.txt)) }
## Xcursor() { reply=($(awk '/^#define/ {print $2}' \
## </usr/include/X11/cursorfont.h | sed 's/^XC_//')) }
## compctl -k '(-help -def -display -cursor -cursor_name -bitmap -mod -fg -bg
##   -grey -rv -solid -name)' -x 'c[-1,-display]' -k hosts -S ':0.0' - \
##   'c[-1,-cursor]' -f -  'c[-2,-cursor]' -f - \
##   'c[-1,-bitmap]' -g '/usr/include/X11/bitmaps/*' - \
##   'c[-1,-cursor_name]' -K Xcursor - \
##   'C[-1,-(solid|fg|bg)]' -K Xcolours -- xsetroot
## 
## # Default completion.  See func/multicomp
## compctl -D -f + -U -K multicomp
## # If completion of usernames is slow for you, you may want to add something
## # like
## #    -x 'C[0,*/*]' -f - 's[~]' -S/ -k users + -u
## # where `users' contains the names of the users you want to complete often.
## # If you want to use this and to be able to complete named directories after
## # the `~' you should add `+ -n' at the end


# su takes an username and args for the shell, the `-c' case is
# handled specially here
compctl -u -x 'w[2,-c] p[3,-1]' -l '' -- su

# There are (at least) two ways to complete manual pages.  This one is
# extremely memory expensive if you have lots of man pages
man_var() {
  man_pages=( $^manpath/man*/*(N:t:r) )   # Check your setting of SH_WORD_SPLIT
  compctl -k man_pages man
  reply=( $man_pages )
}
compctl -K man_var man
# This one isn't that expensive but somewhat slower
man_glob () {
  local a
  read -cA a
  if [[ $a[2] = -s ]] then         # Or [[ $a[2] = [0-9]* ]] for BSD
    reply=( $^manpath/man$a[3]/$1*$2(N:t:r) )    # See above
  elif [[ $a[2] = [0-9]* ]] then
    reply=( $^manpath/(man|cat)$a[2]/$1*$2(N:s/.gz//:t:r))
  else
    reply=( $^manpath/(man|cat)*/$1*$2(N:s/.gz//:t:r))    # See above
  fi
}
compctl -K man_glob man

# Misc.
compctl -s '$(groups)' newgrp
compctl -f -x 'p[1]' -s '$(groups)' -- chgrp
compctl -f -x 'p[1]' -u -- chown
## compctl -g '*.x' + -g '*(-/)' rpcgen
## compctl -u -x 's[+] c[-1,-f],s[-f+]' -g '~/Mail/*(:t)' - \
##   's[-f],c[-1,-f]' -f -- mail elm

# Some builtins.
compctl -j -P % fg bg wait jobs disown
compctl -A shift
compctl -caF whence which
compctl -F unfunction
compctl -a unalias
compctl -v unset typeset declare vared readonly export integer
compctl -e disable
compctl -d enable
compctl -k '(cputime filesize datasize stacksize coredumpsize resident \
  memoryuse memorylocked descriptors openfiles vmemorysize)' limit u{n,}limit
compctl -l '' -x 'p[1]' -f -- . source

## # Various MH completions by Peter Stephenson
## # Still to do:
## # Support for searching for files in standard MH locations.
## 
## # mhcomp is best autoloaded.  Edit path where indicated.
## function mhcomp {
##   # Completion function for MH folders.
##   # Works with both + (rel. to top) and @ (rel. to current).
##   local nword args pref char mhpath
##   integer ngtrue
##   read -nc nword
##   read -cA args
## 
##   [[ -o nullglob ]] && ngtrue=1 || setopt nullglob
## 
##   pref=$args[$nword]
##   char=$pref[1]
##   pref=$pref[2,-1]
## 
## # The `...`'s here account for most of the time spent in this function.
##   if [[ $char = + ]]; then
## #    mhpath=`mhpath +`
## # EDIT ME:  Use a hard wired value here: it's faster.
##     mhpath=~/Mail
##   elif [[ $char = @ ]]; then
##     mhpath=`mhpath`
##   fi
## 
##   reply="reply=($mhpath/$pref*(-/))"
##   eval $reply
## 
##   # I'm frankly amazed that this next step works, but it does.
##   reply=(${reply#$mhpath/})
## 
##   (( ngtrue )) || unsetopt nullglob
## }
## 
## mhfseq() { set -A reply $(mark | awk -F: '{print $1}') \
## next cur prev first last all unseen }
## 
## compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
##   's[-]' -k '(all fast nofast header noheader help list nolist \
##   pack nopack pop push recurse norecurse total nototal)' -- folder
## compctl -K mhfseq -x 's[+][@],c[-1,-draftfolder] s[+][@]' \
##   -K mhcomp -S / -q - 'c[-1,-draftmessage]' -K mhfseq - \
##   'C[-1,-(editor|whatnowproc)]' -c - \
##   's[-]' -k '(draftfolder draftmessage nodraftfolder editor noedit \
##   file form use nouse whatnowproc nowhatnowproc help)' -- comp
## compctl -K mhfseq + -x 's[+][@]' -K mhcomp -S / -q - \
##   's[-]' -k '(audit noaudit changecur nochangecur form format \
##   file silent nosilent truncate notruncate width help)' - \
##   'C[-1,-(audit|form|file)]' -f -- inc
## compctl -K mhfseq -x 's[+][@],C[-1,-src] s[+][@]' \
##   -K mhcomp -S / -q - 'c[-1,-file]' -f - 'c[-1,-rmmprov]' -c - \
##   's[-]' -k '(draft link nolink preserve nopreserve src file \
##   rmmproc normmproc help)' -- refile
## compctl -K mhfseq -x 's[+][@],C[-1,-(draftfolder|fcc)] s[+][@]' \
##   -K mhcomp -S / -q - 'c[-1,-draftmessage]' -K mhfseq -\
##   's[-]' -k '(annotate noannotate cc nocc draftfolder nodraftfolder \
##   draftmessage editor noedit fcc filter form inplace noinplace query \
##   noquery width whatnowproc nowhatnowproc help)' - 'c[-1,(cc|nocc)]' \
##   -k '(all to cc me)' - 'C[-1,-(filter|form)]' -f - \
##   'C[-1,-(editor|whatnowproc)]' -c -- repl
## compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
##   's[-]' -k '(clear noclear form format header noheader reverse noreverse \
##   file help width)' - 'C[-1,-(file|form)]' -f -- scan
## compctl -K mhfseq -x 's[+][@]'  -K mhcomp -S / -q - \
##   's[-]' -k '(draft header noheader showproc noshowproc)' - \
##   'c[-1,showproc]' -c -- show
## compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - 's[-]' \
##   -k '(help)' -- rmm

compctl -o setopt unsetopt
compctl -b bindkey

glob_folders () {
	reply=(`cat ~/Mail/.folders`)
}

compctl -g "~/Mail/*(/)(:t)" 			   refn
compctl -k "(all cur first last next prev unseen)" -S : -x \
	'S[+]' -K glob_folders				-- inc show scan

# End of MH completions

###
# for archivers
##
compctl -f -x 'C[-1,*f*] p[2]' -g "(|.)*.tar (|.)*(-/)" -- tar
compctl -f -x \
	's[--]' -k "(atime-preserve remove-files exclude help)" - \
	'C[-1,*z*] p[2]' -g "*.tar.(Z|z|gz) *.taz *.tgz (|.)*(-/)" - \
	'C[-1,*y*] p[2]' -g "*.tar.(bz(|2)) *.tbz (|.)*(-/)" - \
	'C[-1,*f*] p[2]' -g "*.tar (|.)*(-/)"		-- gtar
###
# for directory operators
###
# Rmdir only real directories
compctl -g '(|.)*(-/)' rmdir dircmp rd mdcd mkdir
compctl -x 'p[2]' -k "(wheel staff ftpadmin okoma)"	-- pubmd

###
# for hostname-sensitive commands
###
compctl -u -S @ -x \
	'n[5,,]' -k hostnames -S '' - \
	'n[4,,]' -k hostnames -S '' - \
	'n[3,,]' -k hostnames -S '' - \
	'n[2,,]' -k hostnames -S '' - \
	'n[1,,]' -k hostnames -S '' - \
	'n[*,{]' -k hostnames -S , - \
	'n[1,@]' -k hostnames - \
	'S[.]' -k '(.local)' -S @ - \
	's[-]' -k'(m l s q i b f w h p)'		-- finger
compctl -u -S @ -x 'n[1,@]' -k hostnames		-- talk phone
compctl -k hostnames + -k ftpsites	ping {,nc}ftp telnet traceroute spray

compctl -k hostnames -x \
	'c[-1,-l]' -u - \
	'p[4,-1]' -l '' - \
	'p[2,-1]' -l ''			-- scrsh rlogin

compctl -k hostnames -S : + -f -x \
	'n[1,:]' -g "(.|)*" -- scp rcp rsync
	
###
# for variable-aware commands
###
# Default completion at argc[0]
if [[ $ZSH_VERSION > "3.0" ]]; then
 compctl -C -c -x \
	's[DISPLAY=]' -k hostnames -S ":0" - \
	's[LANG=]' -k '(japanese C)' - \
	's[TERM=]' -k '(vt100 kterm xterm news screen pc3 cons25)' - \
	's[LESSCHARSET=]' -k '(japanese jis sjis ujis)' - \
	'C[0,[A-Z][A-Z][A-Z_]*]' -v -S = + \
	  -k '(LANG JAPANESE LESSCHARSET DISPLAY LD_LIBRARY_PATH)' -S = - \
	'n[1,=]' -f
else
 compctl -C -c -x \
	's[DISPLAY=]' -k hostnames -S ":0" - \
	's[LANG=]' -k (japanese C) - \
	's[TERM=]' -k (vt100 kterm xterm news screen pc3 cons25) - \
	's[LESSCHARSET=]' -k (japanese jis sjis ujis) - \
	'C[0,[A-Z][A-Z][A-Z_]*]' -v \
		-k (LANG JAPANESE LESSCHARSET DISPLAY LD_LIBRARY_PATH) -S = - \
	'n[1,=]' -f
fi
# Default completion maybe right of parameter assignment
compctl -D -f -x \
	'C[-1,DISPLAY=*]' -k hostnames -S ":0" - \
	'C[-1,LANG=*]' -k "(japanese C)" - \
	'C[-1,PAGER=*]' -k "(less more)" - \
	'C[-1,TERM=*]' -k "(vt100 kterm xterm news screen)" - \
	'C[-1,*PATH*=*]' -f - \
	'C[-1,LESSCHARSET=*]' -k "(japanese jis sjis ujis)"

# setenv (personal function)
compctl -f -x \
	'p[1]' -v + -k "(LANG DISPLAY TERM LESSCHARSET)" - \
	'c[-1,DISPLAY]' -k hostnames -S ":0" - \
	'c[-1,LANG]' -k "(japanese C)" - \
	'c[-1,PAGER]' -k "(less more)" - \
	'c[-1,TERM]' -k "(vt100 kterm xterm news screen)" - \
	'c[-1,LESSCHARSET]' -k "(japanese jis sjis ujis)" 	-- setenv

# Similar things for tex, texinfo and dvi files.
compctl -g '*.tex*' + -g '*(-/)' {big,}{J,j,}latex {big,}{J,j,}tex
compctl -g '*.dvi' + -g '*(-/)' -x \
	'c[-1,-o]' -k "(landscape a5 b4 b4landscape)"	-- dvi2ps jdvi2kps

###
# for archivers and compression tools
###
compctl -f -x 'p[1,2]' \
	-g "*(-/) *.[Ll][Zz][Hh] *.[Ee][Xx][Ee]"	-- lha lhp
compctl -f -x 'p[1]' -g "*(-/) *.[Aa][Rr][Cc]"		-- arc
compctl -f -x 'p[1,2]' -g "*(-/) *.[Zz][Ii][Pp]"	-- zip unzip
compctl -f -x 'p[1,2]' -g "*(-/) *.[Aa][Rr][Jj]"	-- unarj
compctl -g "*(-/) *.(Z|z|gz)"				zmore zless zgrep zcmp

###
# for printers
###
printers=(sp620 cclbp{9,c})
compctl -f -x 's[-P]' -k "($printers)"			-- lp{r{,m},q}
compctl -f -x 'p[1]' -k "(abort enable disable help restart status topq \
			clean down start stop up)" - \
	'p[2]' -k "($printers)"				-- lpc
unset printers

###
# for X-window
###
winopt=(geometry display fg bg fn popup_geometry)
# The next line is the template
# 's[-]' -k winopt - 'c[-1,-display]' -k hostnames -S ':0 '
compctl -x \
	's[-]' -k winopt - 'c[-1,-display]' -k hostnames -S ':0 ' - \
	'c[-1,-geometry]' -k "(+0+0 80x37+0+0 80x26+0+0)" -- kterm xterm
compctl -g '*.dvi *(-/)' -x \
	's[-]' -k "($winopt s S p l paper keep rv)" - \
	'c[-1,-paper]' -k "(a4r)" - \
	'c[-1,-display]' -k hostnames -S ':0 '		-- xdvi
compctl -g "*.ps *.eps ^*.* *(-/)" -x \
	's[-]' -k winopt - 'c[-1,-display]' -k hostnames -S ':0 ' \
							 -- ghostview gs
compctl -caF -x \
	'p[1]' -k hostnames - \
	'c[-1,-l]' -k "(yuuji)" - \
	's[-]' -k winopt - 'c[-1,-display]' -k '($DISPLAY)' -S ' ' - \
	'p[2,-1]' -l '' 				-- rsh rs

compctl -caF -x \
	'p[1]' -k hostnames - \
	'c[-1,-l]' -k "(yuuji)" - \
	'C[-1,-[RL]] C[0,[0-9]*] n[1,:]' -k hostnames -S : - \
	's[-]' -k winopt - 'c[-1,-display]' -k '($DISPLAY)' -S ' ' - \
	'C[-2,-[RLlp]][-1,-[fnqPtvxC]]' -k hostnames - \
	'p[-1]' -l ''				      -- ssh

compctl -caF -x 'p[1]' -k hostnames - \
	'c[-1,kterm] s[-]' -k '(fn fl fk T)' - \
	'p[2,-1]' -l '' - \
	'c[-1,-fl]' \
	 -k '("-*-fixed-medium-normal--16-iso*")' \
	 -S ' -fn 8x16 -fk kanji16&' - \
				 			-- xon xrsh
compctl -x \
	's[-]' -k winopt - \
	'c[-1,-display]' -k hostnames -S ':0 ' - \
	'c[-1,-file]' -f - \
	'C[-1,-*geometry]' -k '(+0+0 +400+0 -0+0)'	-- xpbiff xbiff

compctl -f -x \
	's[-]' -k winopt + -k \
	'(owncmap expand gamma aspect best24 mono wait nolimits 2xlimit)' - \
	'C[-1,-geometry]' -k '(+1+1)'			-- xv xv8


glob_netscape () {
	local n a p
	read -cA a
	read -cn n
	p=`echo $a[$n]|sed 's,.*~yuuji/,,'`
	reply=(~/http/$^p*(N:s,$HOME/http/,,))
}

compctl -x \
	's[http://vfr/~yuuji/]' -K glob_netscape	-- netscape

# C compilers
compctl -g "*.[cCoa]" -x 's[-I][-L]' -g "*(/)" - \
	'C[-1,-o]' -g "*.c(:r)" - \
	's[-l]' -s '${(s.:.)^LD_LIBRARY_PATH}/lib*.a(:t:r:s/lib//) \
		/usr/{,*/}lib/lib*.a(:t:r:s/lib//)'	-- cc gcc

# Java compiler and interpreter
compctl -g "*(-/) *.java"				javac
compctl -g "*.class(:r)" -x \
	'p[2,-1]' -f					-- java kaffe

###
# for netpbm
###
compctl -f -x 's[-]' -k '(interlace transparent)'	-- ppmtogif
compctl -f -x 'p[1]' -k '(256 200)' -S ' | ppmtogif'	-- ppmquant

###
# for ImageMagick
###
compctl -f -x \
	's[-]' -k '(colors delay gamma geometry interlace monochrome \
		quality rotate)' - \
	'c[-1,-interlace]' -k '(line none plane partition)' -- convert

###
# Miscellaneous
###
# GNU Emacs
compctl -g "^*[#~] .*" -x \
	's[-]' -k "(user nw batch e insert kill load display geometry)" - \
	's[+]' -X "Line number" - \
	'c[-2,-batch] c[-1,-e]' -k "(batch-byte-compile)" - \
	'c[-1,-batch]' -k "(-e)" -S ' batch-byte-compile ' - \
	'c[-1,-e]' -k "(mew mh-rmail mh-smail resume-windows trr)" - \
	'c[-1,-display]' -k hostnames -S ":0 " - \
	'c[-1,-geometry]' -k "(+0+0 80x37+0+0 80x26+0+0)" - \
	'c[-1,-user]' -u		-- mule $emacs m1 tamago canna emacs

compctl -g "*(-/)" -x \
	's[-]' -k '(fstype name perm prune type user nouser group nogroup \
		 size \
		inum atime mtime ctime exec ok print ls cpio ncpio newer \
		xdev depth)' - \
	'c[-1,-type]' -k '(c b d f p l s)' - 'c[-1,-user]' -u - \
	'r[-exec,;][-ok,;]' -l ''			-- find

compctl -x \
	'c[-1,-f]' -g "[Mm]ake* *.[Mm]*[Kk] *(-/)" - \
	's[CC]' -P "='" -k '(gcc cc)' -S " -pipe" - \
	'S[CF]' -S "='" -k '(CFLAGS)' - \
	's[-I],s[-L]' -g "*(-/)"			-- make gmake

compctl -g "(|.)*~*.[ch] *(-/)"				rm

compctl -f -x \
       'c[-1,-man]' -g "*.[0-9] *.man *(-/)"           -- nroff jgroff

compctl -g "(|*).obj *(-/)"				tgif prtgif

compctl -f -x \
	's[-]' -k '(s R mv rm mkindex refresh pick flush perf \
		   delete reclassify)' - \
							-- ftpurl
compctl -g "(|*).(smc|SMC)(|.gz) *(-/)"			snes9x
compctl -g "(|*).(nes|NES)(|.gz) *(-/)"			ines
compctl -x 's[if=],s[of=]' -f				-- dd
compctl -x \
	'n[1,freebsd]' -k '(2.2.8 3.1)' - \
	'n[1,i386]' -k '(-amd-freebsd -intel-freebsd)' - \
	'n[1,i586]' -k '(-amd-freebsd -intel-freebsd)' - \
	'n[1,=]' -k '(yes no)' + -f - \
	's[--]' -k '(prefix disable with-mule program-prefix target \
	 with-canna with-canna-libraries with-canna-includes)' -S '=' - \
	's[i]' -k '(386-amd-freebsd 586-intel-freebsd)' -S '' - \
	'S[s]' -k '(sparc-sun-netbsd1.3.1 sparc-sun-sunos)' -S '' - \
							-- configure conf

glob_syncdir () {
	local n a p=1 table=${SYNCDIRTABLE:-~/.syncdir} lo
	read -cA a		#コマンドライン全体を配列 a に入れる
	read -cn n		#引数の数を n に入れる
	while [[ $p -lt $n ]] {
	 [[ -f $a[$p] && "$lo" = "-f" ]] && table=$a[$p]
	 lo=$a[$p]
	 p=$[++p]
	}
	reply=(`sed -n "/[^A-z]/s/:.*//p" $table`)
}
compctl -g "(.|)*(-/)" -x \
        's[-]' -k '(d l L e n N p x q f V r a A)' - \
        'c[-1,-f]' -f - \
        'c[-1,-V]' -K glob_syncdir                      -- syncdir