# ~/.zshcomp
# (should be sourced by .zshrc)
#
# Z-Shell Completion Options
######################################################################
export ZSHCOMP_VERSION="$Id: .zshcomp,v 1.47 2002/09/14 03:16:20 cwynne Exp cwynne $"
######################################################################
# These are variables to be used by assorted completion rules
######################################################################
# Non-local users on whom I might want to complete (for talk, etc.).
myusers=( )
hosts=( iulius.avtokrator.org octavius.avtokrator.org \
dorian.emufarm.org lorien.emufarm.org \
jesse.mts.jhu.edu joshua.mts.jhu.edu \
cinna.mts.jhu.edu voronoi.mts.jhu.edu \
localhost )
ftpsites=(
ftp.dante.de ftp.shsu.edu \
ftp.tex.ac.uk )
# Suffices to ignore in file completions.
fignore=( .o \~ )
######################################################################
# COMPLETION RULES
######################################################################
## DEFAULT COMPLETION
compctl -C -c + -q -S "=" -E -v
## Command lines.
compctl -x 'p[1,-1]' -l '' -- noglob
## Environment variables.
compctl -E -q -S "=" -x 'n[0,=]' -f -- export
## Shell functions.
compctl -F unfunction functions refunc
## Key bindings.
compctl -b bindkey
## Commands
compctl -c alias exec whence
compctl -c -x 's[-l],c[-1,-l]' -f -- m man
## Glob patterns.
compctl -g '*.dvi' + -g '*(-/)' xdvi dvips 2up dvi2vdu vdu
compctl -g '*.pdf' + -g '*(-/)' acroread
compctl -g '*.ps' + -g '*(-/)' ghostview gs psps pstops \
psselect ps2gif ps2pdf
compctl -g '*.(ps|pdf)' + -g '*(-/)' gv
compctl -g '*(gz|.Z)' + + -g '*(-/)' gunzip zcat zless zmore zgrep
compctl -g '*.zip' + -g '*(-/)' unzip
# cd completes on real dirs or links:
compctl -g '*(-/)' cd
# rmdir completes only on real dirs:
compctl -g '*(/)' rmdir
compctl -f -x 'C[-1,*z*f]' -g '*.(tgz|tar.gz|tar.Z)' + -f \
- 'C[-1,*f]' -g '*.tar' + -f -- tar
compctl -g '*.(tex|ins|dtx|sty)' + -g '*(-/)' \
tex virtex slitex bibtex \
latex etex
compctl -g "$SPOOL/*(:t)" + -g '~/mail/*(:t)' \
cm wm
## Jobs.
## Complete jobnames with a `%' prefix unless we have just started a
## flag word. In that case, do signals.
compctl -j -P% -x 's[-]' -K siglist -- kill disown
## Variables.
compctl -v vared
## User defined arrays.
## FTP Sites:
compctl -k ftpsites ftp ncftp
## Group Names:
##
## Here goes: complete files (-f) unless the extended completion is
## applicable. The extended rule (-x) says to complete something of
## the form <user>.<group> if [we are in the second word *and* the
## previous word matches the pattern `-*' (i.e., consists of flags)]
## or [if this is the first word].
compctl -f -x 'p[2] C[-1,-*] n[0,.],p[1] n[0,.]' -K grouplist \
- 'p[2] C[-1,-*],p[1]' -u -q -S. -- chown
## As above, but only needs group completion.
compctl -f -x 'p[2] C[-1,-*],p[1]' -K grouplist -- chgrp
## Host Names:
compctl -k hosts -x 'c[-1,-l]' -K userlist -- rlogin rsh
compctl -k hosts telnet ping traceroute \
ipalive nslookup mtr nc host
compctl -k hosts -S/ vat
## SSH Hosts:
##
## Complete the current word with files after a `:', with ssh hosts
## after a `@', and with hosts or files (in that order) at the start
## of a word.
compctl -x 'n[0,:]' -f - 'n[0,@],s[]' -k hosts -S: + -f -- scp
## This completes `command [host] [-l user]'.
compctl -k hosts -x 'c[-1,-l]' -K userlist -- slogin
## As above, but do 'ssh [host] [-l user] [command]' where <command>
## is a separate command line (i.e., to be executed via ssh as
## <user> on <host>).
compctl -x 'p[1], p[2] C[-1,-*]' -k hosts \
- 'c[-1,-l]' -K userlist -- \
+ -x 'w[2,-l] p[4,-1],p[2,-1]' -l '' -- ssh
## User Names:
compctl -K userlist -q -S@ -x 'n[0,@]' -k hosts -- fs finger isoff \
ison ntalk talk xtalk
compctl -K userlist -q -S@ -x 'n[0,@]' -k hosts -q -S'\#' -- ytalk
## Mail:
##
## For mail type commands that recognize a folder directory, we
## introduce some trickery... If we are after a folder (-f) flag
## and our folder name starts with `+', complete files with the
## implicit prefix of `~/mail', our folder directory. Otherwise, -f
## gets normal file completion. If we are not completing a folder
## argument, grab addresses from BBDB.
compctl -x 's[+] c[-1,-f],s[-f+]' -f -W ~/mail - \
's[-f],c[-1,-f]' -f -- + -K findaddr \
mail mailx mutt
## Options
compctl -o setopt unsetopt
## Users.
compctl -u killuser info last su whois
## Complete users if the previous word contained a `-u' flag.
compctl -x 'C[-1,-*u*]' -u -- ps
## Variables
compctl -v unset
## Sleeping jobs.
compctl -z -P "%" fg
## User-defined functions.
compctl -K funclist autoload
compctl -K makelist -x 'c[-1,-f]' -f -- \
+ -x 'w[1,-c] p[2,-1]' -l '' -- make logmake
######################################################################
# FUNCTIONS
######################################################################
## Complete e-mail addresses.
function findaddr {
reply=( $(find-addr ~/.bbdb) )
}
## Get loadable functions in $FPATH.
function funclist {
reply=( )
for dir in $fpath; do
reply=( $reply $dir/*(X:t) )
done
}
## Get targets from makefile in current directory.
function makelist {
reply=( )
if [[ -a ./GNUmakefile ]]; then
_makefile=./GNUmakefile
elif [[ -a ./makefile ]]; then
_makefile=./makefile
elif [[ -a ./Makefile ]]; then
_makefile=./Makefile
else
reply=( )
return
fi
_lists=( )
_targets=( $(grep : $_makefile | cut -d: -f1) )
for str in $_targets; do
if [[ ${(S)str#\(*\)} = $str ]]; then
reply=( $reply $str)
# else
# _lists=( $_lists ${(SM)str#\(*\)} )
fi
done
# _temp1=( ${_lists#\(} )
# _lists=( ${_temp1%\)} )
_temp1=( $(grep \\.o $_makefile) )
for str in $_temp1; do
[[ $str == *.o && $str != "*.o" ]] && reply=( $reply $str )
done
unset _makefile
}
## Get a list of valid signals.
function siglist {
reply=( $(kill -l) )
}
## Generate a list of groups.
function grouplist {
reply=( )
if [[ -n $NIS_PATH ]]; then
reply=( $(niscat group | cut -d: -f1) )
else
reply=( $(cat /etc/group | cut -d: -f1) )
fi
}
## Generate a list of users.
function userlist {
reply=( )
if [[ -n $NIS_PATH ]]; then
reply=( $(niscat passwd | cut -d: -f1) )
else
reply=( $(cat /etc/passwd | cut -d: -f1) )
fi
reply=( $myusers $reply )
}
######################################################################
# END
######################################################################