hosts=(`sed 's/\([0-9]*\.\)*[0-9]*//'</etc/hosts`)
ports=(`gawk '{print $1}' < /etc/services`)
groups=(`gawk -F: '{print $1}' < /etc/group`)

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) )
   else
     reply=( ${^manpath}/man*/$1*$2(N:t:r) )
   fi
}

compctl -/ cd chdir dirs pushd
compctl -g '*(/)' rmdir dircmp
compctl -j -P % -x 's[-] p[1]' -k signals -- kill
compctl -j -P % fg bg wait jobs disown
compctl -A shift
compctl -caF type whence which nohup
compctl -F unfunction
compctl -a unalias
compctl -v unset typeset declare vared readonly export integer
compctl -e disable
compctl -d enable
compctl -/g '*.(gz|z|Z|t[agp]z|tarZ|tz)' gunzip gzcat zcat
compctl -K man_glob -x 'C[-1,-P]' -m - \
	'R[-*l*,;]' -/g '*.(man|[0-9nlpo](|[a-z]))' -- man
compctl -k hosts \
	-x "c[-1,-l]" -u \
	- "c[-1,-i]" -f \
	- "c[-1,-e]" -k "(~ none)" \
	- "c[-1,-c]" -k "(twofish idea des 3des tss arcfour none)" \
	- "c[-1,-p]" -k ports \
	- "c[-1,-L] c[-1,-R] c[-1,-o]" -k "()" \
	-- ssh
compctl -k hosts \
	-x "C[-1,[^-]*] p[2,-1]" -k ports \
	-- telnet
if [[ -r /proc/filesystems ]]; then
    # Linux
    filesystems='"${${(f)$(</proc/filesystems)}#*	}"'
else
    filesystems='ufs 4.2 4.3 nfs tmp mfs S51K S52K'
fi
compctl -x 'r[-exec,;][-ok,;]' -l '' - \
's[-]' -s 'daystart {max,min,}depth follow noleaf version xdev
	{a,c,}newer {a,c,m}{min,time} empty false {fs,x,}type gid inum links
	name {no,}{user,group} path perm regex size true uid used mount
	exec {f,}print{f,0,} ok prune ls' - \
	'p[1]' -g '. .. *(-/)' - \
	'C[-1,-((a|c|)newer|fprint(|0|f))]' -f - \
	'c[-1,-fstype]' -s $filesystems - \
	'c[-1,-group]' -k groups - \
	'c[-1,-user]' -u -- find

if [ -d ~/.netscape ]
then
	urls=( \
		`grep \<A ~/.netscape/bookmarks.html | grep -v file: |\
		sed -e 's/.*HREF\=\"//' -e 's/\".*//'`\
		)
fi
compctl -k urls -x 'c[-1,-O]' -f -- wget
compctl -k urls + -f netscape
compctl -k urls + -f moz
compctl -k hosts ping

configre_opts () {
	reply=( `./configure --help | awk '/--/{print $1}' |\
	sed -e 's/=.*//'` )
	}
compctl -K configre_opts -S '=' -q -x 'n[-1,=]' -f -- configure
compctl -f -x 's[-]' \
	-s 'display all global screen screens n cpp nocpp query load
	override merge edit backup symbols remove retain quiet Dname='\
	-- xrdb
compctl -/g '*.bz2' bunzip2 bzcat
compctl -/g '*.dvi' xdvi dvips
compctl -/g '*.tex' + -f jlatex latex tex
compctl -/g '*jpg *jpeg *tif *tiff *png \
	*tga \
	*gif *xpm *ppm *bmp *xbm \
	*xcf.gz *xcf.bz2 *xcf'\
	+ -f gimp
compctl -/g '*jpeg *jpg *tif *tiff *png \
	*tga \
	*gif *xpm *ppm *bmp *xbm'\
	+ -f ee xv wmsetbg
compctl -f -x 'p[1] n[-1,.], p[2] C[-1,-*] n[-1,.]' -k groups - \
	'p[1], p[2] C[-1,-*]' -u -S '.' -q -- chown
compctl -f -x 'p[1], p[2] C[-1,-*]' -k groups -- chgrp

make_targets () {
	if [ -f ./Makefile ]
	then
	reply=( `grep \^\(\ \*\[\--z\]\*\ \*\)\*\: ./Makefile | sed 's/:.*//'` )
	else
	reply=()
	fi
	}
compctl -K make_targets make
xlock_opts () {
	reply=( `xlock -help | awk '{print $1}'| grep -- - | sed 's/\/+//'`)
	}
xlock_modes () {
	reply=( `xlock -help | awk '{print $1}'|grep -v -- -` )
	}
compctl	-K xlock_opts \
-x 'c[-1,-mode]' -K xlock_modes -- \
xlock
compctl -u su
running_process () {
	reply=(` ps ax| awk '{print $5}'`)
	}
compctl -K running_process + -caF ikill pid
compctl -f -x 'c[-1,+i]' -/g '*pov' -- povray
compctl -/g '*mp3' + -f x11amp mpg123 replay newplayer xmms
compctl -x 'n[-1,=]' -f -- dd
compctl -M 'm:{a-z}={A-Z}' 'r:|[.,_-]=* r:|=*' 'l:|=* r:|=*'

# Belows doesn't work in zsh-3.1.6.
#hosts=("${${(s: :)${(s:	:)${${(f)$(</etc/hosts)}%%\#*}#*[ 	]*}}:#}")
#groups=( "${${(f)$(</etc/group)}%%:*}" )
#ports=( "${${${(f)$(</etc/services)}:#\#*}%%[ 	]*}" )
