set noglob
# get me a list of known host names to use in completions
if ( ! $?hosts ) set hosts
  foreach f ($HOME/.hosts $HOME/.tcshrc.hosts $HOME/.rhosts /etc/hosts.equiv)
    if ( -r $f ) then
      set hosts = ($hosts `grep -v "+" $f | egrep -v "^#" | tr -s " " "	" | cut -f 1`)
    endif
  end
  if ( -r $HOME/.ssh/known_hosts ) then
    #set f=`cat $HOME/.ssh/known_hosts | cut -f 1 -d \  | sed -e 's/,.*//g' -e 's/:.*//g' -e 's/\[//g' -e 's/\]//g' | sort -u` >& /dev/null
    if ("$type" == "Linux") then
      set f=`cut -f 1 -d \  < $HOME/.ssh/known_hosts | sed -re 's/,/ /g' -e 's/:[[:digit:]]+//g' -e 's/\[//g' -e 's/\]//g' | sort -u` >& /dev/null
      set hosts=($hosts $f)
    endif
  endif
  unset f
endif

#if (-r /proc/modules) then
#  set KernelRevision=`uname -r`
#  if (-d /lib/modules/$KernelRevision) then
#    set LoadedModules=`cat /proc/modules | cut -d' ' -f1`
#    set AvailableModules=`find /lib/modules/$KernelRevision -name "*.ko" -print | awk -F/ '{print $NF}' | sed -e 's/.ko$//'`
#    complete rmmod p/1/\$LoadedModules/ c/-/"(l n)"/   n/-l/u/ N/-l/c/ n/-/c/ p/2/c/ p/*/f/
#    complete modprobe p/1/\$AvailableModules/ c/-/"(l n)"/   n/-l/u/ N/-l/c/ n/-/c/ p/2/c/ p/*/f/
#  endif
#endif

complete ssh	p/1/\$hosts/ c/-/"(l n)"/   n/-l/u/ N/-l/c/ n/-/c/ p/2/c/ p/*/f/

complete cd  	p/1/d/		# Directories only
complete rmdir 	p/1/d/		# Directories only
complete exec 	p/1/c/		# Commands only
complete trace 	p/1/c/
complete strace 	p/1/c/
complete which	n/*/c/
complete where	n/*/c/
complete unset	n/*/s/
complete alias 	p/1/a/		# only aliases are valid
complete unalias	n/*/a/
complete cc 	c/-[IL]/d/ \
              c@-l@'`\ls -1 /usr/lib/lib*.a | sed s%^.\*/lib%%\;s%\\.a\$%%`'@ \
			c/-/"(o l c g L I D U)"/ n/*/f:*.[coasi]/
complete gcc 	c/-[IL]/d/ \
		 	c/-f/"(caller-saves cse-follow-jumps delayed-branch \
		               elide-constructors expensive-optimizations \
			       float-store force-addr force-mem inline \
			       inline-functions keep-inline-functions \
			       memoize-lookups no-default-inline \
			       no-defer-pop no-function-cse omit-frame-pointer \
			       rerun-cse-after-loop schedule-insns \
			       schedule-insns2 strength-reduce \
			       thread-jumps unroll-all-loops \
			       unroll-loops syntax-only all-virtual \
			       cond-mismatch dollars-in-identifiers \
			       enum-int-equiv no-asm no-builtin \
			       no-strict-prototype signed-bitfields \
			       signed-char this-is-variable unsigned-bitfields \
			       unsigned-char writable-strings call-saved-reg \
			       call-used-reg fixed-reg no-common \
			       no-gnu-binutils nonnull-objects \
			       pcc-struct-return pic PIC shared-data \
			       short-enums short-double volatile)"/ \
		 	c/-W/"(all aggregate-return cast-align cast-qual \
		      	       comment conversion enum-clash error format \
		      	       id-clash-len implicit missing-prototypes \
		      	       no-parentheses pointer-arith return-type shadow \
		      	       strict-prototypes switch uninitialized unused \
		      	       write-strings)"/ \
		 	c/-m/"(68000 68020 68881 bitfield fpa nobitfield rtd \
			       short c68000 c68020 soft-float g gnu unix fpu \
			       no-epilogue)"/ \
		 	c/-d/"(D M N)"/ \
		 	c/-/"(f W vspec v vpath ansi traditional \
			      traditional-cpp trigraphs pedantic x o l c g L \
			      I D U O O2 C E H B b V M MD MM i dynamic \
			      nodtdlib static nostdinc undef)"/ \
		 	c/-l/f:*.a/ \
		 	n/*/f:*.{c,C,cc,o,a,s,i}/
complete g++ 	n/*/f:*.{C,cc,o,s,i}/
complete CC 	n/*/f:*.{C,cc,cpp,o,s,i}/
complete find 	n/-fstype/"(nfs 4.2)"/ n/-name/f/ \
		  	n/-type/"(c b d f p l s)"/ n/-user/u/ n/-group/g/ \
			n/-exec/c/ n/-ok/c/ n/-cpio/f/ n/-ncpio/f/ n/-newer/f/ \
		  	c/-/"(fstype name perm prune type user nouser \
		  	     group nogroup size inum atime mtime ctime exec \
			     ok print ls cpio ncpio newer xdev depth \
			     daystart follow maxdepth mindepth noleaf version \
			     anewer cnewer amin cmin mmin true false uid gid \
			     ilname iname ipath iregex links lname empty path \
			     regex used xtype fprint fprint0 fprintf \
			     print0 printf not a and o or)"/ \
			     n/*/d/

complete zcat	n/*/f:*.{Z,gz}/
complete finger	c/*@/\$hosts/ n/*/u/@ 
complete ping	p/1/\$hosts/
complete traceroute	p/1/\$hosts/

complete ftp	c/-/"(d i g n v)"/ n/-/\$hosts/ p/1/\$hosts/ n/*/n/

complete ar c/[dmpqrtx]/"(c l o u v a b i)"/ p/1/"(d m p q r t x)"// \
		p/2/f:*.a/ p/*/f:*.o/

complete ./configure 'c/--*=/f/' 'c/--{cache-file,prefix,exec-prefix,\
    				bindir,sbindir,libexecdir,datadir,\
				sysconfdir,sharedstatedir,localstatedir,\
				libdir,includedir,oldincludedir,infodir,\
				mandir,srcdir}/(=)//' \
			 'c/--/(cache-file verbose prefix exec-prefix bindir \
			 	sbindir libexecdir datadir sysconfdir \
				sharedstatedir localstatedir libdir \
				includedir oldincludedir infodir mandir \
				srcdir)//'
complete perl	'n/-S/c/'
complete printenv	'n/*/e/'
complete setenv	'p/1/e/' 'c/*:/f/'

complete acroread	'p/*/f:*.{pdf,PDF}/'
complete bison	'c/--/(debug defines file-prefix= fixed-output-files \
			help name-prefix= no-lines no-parser output= \
			token-table verbose version yacc)/' \
			'c/-/(b d h k l n o p t v y V)/' 'n/-b/f/' 'n/-o/f/' \
			'n/-p/f/'
complete bzip2	'n/-9/f:^*.bz2/' 'n/-d/f:*.bz2/'
complete c++	'p/*/f:*.{c++,cxx,c,cc,C,cpp}/'
#complete ifconfig	'p@1@`ifconfig -l`@' 'n/*/(range phase link netmask \
			#mtu vlandev vlan metric mediaopt down delete \
			#broadcast arp debug)/'
complete imake	'c/-I/d/'
#complete netstat	'n@-I@`ifconfig -l`@'
complete gmake	'c/{--directory=,--include-dir=}/d/' \
			'c/{--assume-new,--assume-old,--makefile,--new-file,--what-if,--file}/f/' \
			'c/--/(assume-new= assume-old= debug directory= \
			dry-run environment-overrides file= help \
			ignore-errors include-dir= jobs[=N] just-print \
			keep-going load-average[=N] makefile= max-load[=N] \
			new-file= no-builtin-rules no-keep-going \
			no-print-directory old-file= print-data-base \
			print-directory question quiet recon silent stop \
			touch version warn-undefined-variables what-if=)/' \
			'n@*@`cat -s GNUMakefile Makefile makefile |& sed -n -e "/No such file/d" -e "s/^\([A-Za-z0-9-]*\):.*/\1/p"`@' \
			'n/=/f/' 'n/-f/f/'
complete mpg123	'c/--/(2to1 4to1 8bit aggressive au audiodevice \
    			auth buffer cdr check doublespeed equalizer frames \
			gain halfspeed headphones left lineout list mix mono \
			proxy quiet random rate reopen resync right scale \
			shuffle single0 single1 skip speaker stdout stereo \
			test verbose wav)/' 'p/*/f:*.{mp2,mp3}/'
complete mysqladmin	'n/*/(create drop extended-status flush-hosts \
			flush-logs flush-status flush-tables flush-privileges \
			kill password ping processlist reload refresh \
			shutdown status variables version)/'
complete nmap	'n@-e@`ifconfig -l`@' 'p/*/$hostnames/'
complete which	'n/*/c/'

if (! $?MANPATH) then
  if (-r /usr/share/man) then
    setenv MANPATH /usr/share/man:/usr/local/share/man
  else
    setenv MANPATH /usr/man:/usr/local/man
  endif
endif
complete man \
	    'n@1@`set q = "$MANPATH:as%:%/man1 %" ; \ls -1 $q |& sed -e s%^.\*:.\*\$%% -e s%\\.1.\*\$%%`@'\
	    'n@2@`set q = "$MANPATH:as%:%/man2 %" ; \ls -1 $q |& sed -e s%^.\*:.\*\$%% -e s%\\.2.\*\$%%`@'\
	    'n@3@`set q = "$MANPATH:as%:%/man3 %" ; \ls -1 $q |& sed -e s%^.\*:.\*\$%% -e s%\\.3.\*\$%%`@'\
	    'n@4@`set q = "$MANPATH:as%:%/man4 %" ; \ls -1 $q |& sed -e s%^.\*:.\*\$%% -e s%\\.4.\*\$%%`@'\
	    'n@5@`set q = "$MANPATH:as%:%/man5 %" ; \ls -1 $q |& sed -e s%^.\*:.\*\$%% -e s%\\.5.\*\$%%`@'\
	    'n@6@`set q = "$MANPATH:as%:%/man6 %" ; \ls -1 $q |& sed -e s%^.\*:.\*\$%% -e s%\\.6.\*\$%%`@'\
	    'n@7@`set q = "$MANPATH:as%:%/man7 %" ; \ls -1 $q |& sed -e s%^.\*:.\*\$%% -e s%\\.7.\*\$%%`@'\
	    'n@8@`set q = "$MANPATH:as%:%/man8 %" ; \ls -1 $q |& sed -e s%^.\*:.\*\$%% -e s%\\.8.\*\$%%`@'\
	    'n@9@`set q = "$MANPATH:as%:%/man9 %" ; \ls -1 $q |& sed -e s%^.\*:.\*\$%% -e s%\\.9.\*\$%%`@'\
	    'n@0@`set q = "$MANPATH:as%:%/man0 %" ; \ls -1 $q |& sed -e s%^.\*:.\*\$%% -e s%\\.0.\*\$%%`@'\
	    'n@n@`set q = "$MANPATH:as%:%/mann %" ; \ls -1 $q |& sed -e s%^.\*:.\*\$%% -e s%\\.n.\*\$%%`@'\
	    'n@o@`set q = "$MANPATH:as%:%/mano %" ; \ls -1 $q |& sed -e s%^.\*:.\*\$%% -e s%\\.o.\*\$%%`@'\
	    'n@l@`set q = "$MANPATH:as%:%/manl %" ; \ls -1 $q |& sed -e s%^.\*:.\*\$%% -e s%\\.l.\*\$%%`@'\
	    'n@p@`set q = "$MANPATH:as%:%/manp %" ; \ls -1 $q |& sed -e s%^.\*:.\*\$%% -e s%\\.p.\*\$%%`@'\
	    c@-@"(- f k M P s S t)"@ n@-f@c@ n@-k@x:'<keyword>'@ n@-[MP]@d@   \
	    'N@-[MP]@`\ls -1 $:-1/man? |& sed -n s%\\..\\+\$%%p`@'            \
	    'n@-[sS]@`\ls -1 $MANPATH:as%:% % |& sed -n s%^man%%p | sort -u`@'\
	    'n@*@`find $MANPATH:as%:% % \( -type f -o -type l \) -printf "%f " |& sed -e "s%find: .*: No such file or directory%%" -e "s%\([^\.]\+\)\.\([^ ]*\) %\1 %g"`@'
	    #n@*@c@ # old way -- commands only

complete xpdf	c/-/"(z g remote raise quit cmap rgb papercolor       \
			      eucjp t1lib freetype ps paperw paperh level1    \
			      upw fullscreen cmd q v h help)"/                \
			n/-z/x:'<zoom (-5 .. +5) or "page" or "width">'/      \
			n/-g/x:'<geometry>'/ n/-remote/x:'<name>'/            \
			n/-rgb/x:'<number>'/ n/-papercolor/x:'<color>'/       \
			n/-{t1lib,freetype}/x:'<font_type>'/                  \
			n/-ps/x:'<PS_file>'/ n/-paperw/x:'<width>'/           \
			n/-paperh/x:'<height>'/ n/-upw/x:'<password>'/        \
			n/-/f:*.{pdf,PDF}/                                    \
			N/-{z,g,remote,rgb,papercolor,t1lib,freetype,ps,paperw,paperh,upw}/f:*.{pdf,PDF}/ \
			N/-/x:'<page>'/ p/1/f:*.{pdf,PDF}/ p/2/x:'<page>'/

complete zcat	c/--/"(force help license quiet version)"/ \
			c/-/"(f h L q V -)"/ n/*/f:*.{gz,Z,z,zip}/
complete gzip	c/--/"(stdout to-stdout decompress uncompress \
			force help list license no-name quiet recurse \
			suffix test verbose version fast best)"/ \
			c/-/"(c d f h l L n q r S t v V 1 2 3 4 5 6 7 8 9 -)"/\
			n/{-S,--suffix}/x:'<file_name_suffix>'/ \
			n/{-d,--{de,un}compress}/f:*.{gz,Z,z,zip,taz,tgz}/ \
			N/{-d,--{de,un}compress}/f:*.{gz,Z,z,zip,taz,tgz}/ \
			n/*/f:^*.{gz,Z,z,zip,taz,tgz}/
complete {gunzip,ungzip} c/--/"(stdout to-stdout force help list license \
			no-name quiet recurse suffix test verbose version)"/ \
			c/-/"(c f h l L n q r S t v V -)"/ \
			n/{-S,--suffix}/x:'<file_name_suffix>'/ \
			n/*/f:*.{gz,Z,z,zip,taz,tgz}/
complete zgrep	c/-*A/x:'<#_lines_after>'/ c/-*B/x:'<#_lines_before>'/\
			c/-/"(A b B c C e f h i l n s v V w x)"/ \
			p/1/x:'<limited_regular_expression>'/ N/-*e/f/ \
			n/-*e/x:'<limited_regular_expression>'/ n/-*f/f/ n/*/f/
complete zegrep	c/-*A/x:'<#_lines_after>'/ c/-*B/x:'<#_lines_before>'/\
			c/-/"(A b B c C e f h i l n s v V w x)"/ \
			p/1/x:'<full_regular_expression>'/ N/-*e/f/ \
			n/-*e/x:'<full_regular_expression>'/ n/-*f/f/ n/*/f/
complete zfgrep	c/-*A/x:'<#_lines_after>'/ c/-*B/x:'<#_lines_before>'/\
			c/-/"(A b B c C e f h i l n s v V w x)"/ \
			p/1/x:'<fixed_string>'/ N/-*e/f/ \
			n/-*e/x:'<fixed_string>'/ n/-*f/f/ n/*/f/
complete znew	c/-/"(f t v 9 P K)"/ n/*/f:*.Z/
complete zmore	n/*/f:*.{gz,Z,z,zip}/
complete zfile	n/*/f:*.{gz,Z,z,zip,taz,tgz}/
complete ztouch	n/*/f:*.{gz,Z,z,zip,taz,tgz}/
complete zforce	n/*/f:^*.{gz,tgz}/

complete grep	c/-*A/x:'<#_lines_after>'/ c/-*B/x:'<#_lines_before>'/\
			c/--/"(extended-regexp fixed-regexp basic-regexp \
			regexp file ignore-case word-regexp line-regexp \
			no-messages revert-match version help byte-offset \
			line-number with-filename no-filename quiet silent \
			text directories recursive files-without-match \
			files-with-matches count before-context after-context \
			context binary unix-byte-offsets)"/ \
			c/-/"(A a B b C c d E e F f G H h i L l n q r s U u V \
				v w x)"/ \
			p/1/x:'<limited_regular_expression>'/ N/-*e/f/ \
			n/-*e/x:'<limited_regular_expression>'/ n/-*f/f/ n/*/f/
complete egrep	c/-*A/x:'<#_lines_after>'/ c/-*B/x:'<#_lines_before>'/\
			c/--/"(extended-regexp fixed-regexp basic-regexp \
			regexp file ignore-case word-regexp line-regexp \
			no-messages revert-match version help byte-offset \
			line-number with-filename no-filename quiet silent \
			text directories recursive files-without-match \
			files-with-matches count before-context after-context \
			context binary unix-byte-offsets)"/ \
			c/-/"(A a B b C c d E e F f G H h i L l n q r s U u V \
				v w x)"/ \
			p/1/x:'<full_regular_expression>'/ N/-*e/f/ \
			n/-*e/x:'<full_regular_expression>'/ n/-*f/f/ n/*/f/
complete fgrep	c/-*A/x:'<#_lines_after>'/ c/-*B/x:'<#_lines_before>'/\
			c/--/"(extended-regexp fixed-regexp basic-regexp \
			regexp file ignore-case word-regexp line-regexp \
			no-messages revert-match version help byte-offset \
			line-number with-filename no-filename quiet silent \
			text directories recursive files-without-match \
			files-with-matches count before-context after-context \
			context binary unix-byte-offsets)"/ \
			c/-/"(A a B b C c d E e F f G H h i L l n q r s U u V \
				v w x)"/ \
			p/1/x:'<fixed_string>'/ N/-*e/f/ \
			n/-*e/x:'<fixed_string>'/ n/-*f/f/ n/*/f/

complete chown	c/--/"(changes dereference no-dereference silent \
    			quiet reference recursive verbose help version)"/ \
			c/-/"(c f h R v -)"/ C@[./\$~]@f@ c/*[.:]/g/ \
			n/-/u/: p/1/u/: n/*/f/
complete chgrp	c/--/"(changes no-dereference silent quiet reference \
    			recursive verbose help version)"/ \
			c/-/"(c f h R v -)"/ n/-/g/ p/1/g/ n/*/f/
complete df		c/--/"(all block-size human-readable si inodes \
			kilobytes local megabytes no-sync portability sync \
			type print-type exclude-type help version)"/ \
			c/-/"(a H h i k l m P T t v x)"/
complete unzip 	p/1/f:*.{zip}/
#complete unrar 	p/2/f:*.{rar}/
complete unrar 	p/2/f:*.{part1.rar,part01.rar,part001.rar,rar}/

unset noglob






set complete = enhance
complete {ee,xv}  'p/*/f:*{.jpg,.png,.gif,.tga,.bmp,.xwd}/'
complete mp3db  'p/*/f:*.mp3/'
complete dtrx  'p/*/f:*{.zip,.rar,.tar,.xz,.gz,.bz2,.lzma,.lz,.gem,.cpiom,.rpm,.deb,.7z,.cab,.msi}/'
complete mkvfix 'p/*/f:*{.mkv}/'
complete wine  'p/*/f:*.exe/'
complete ddts  'p/*/f:*.dts.*/'

complete nice 	p/1/c/		# Commands only
complete time 	p/1/c/		# Commands only

#if ( -e /mp3/playlists) then
#  set PLAYLISTS=`/bin/ls /mp3/playlists/*.m3u | awk -F/ '{print $NF}' | sed -e 's/.m3u//g'` >& /dev/null
#  complete play 'p/*/$PLAYLISTS/'
#endif
