tcshrc Tips

Greg Schenzel <>
  1. Basic Setup
    1. A Righteous umask
    2. A Flexible PATH/MANPATH
    3. Standard Environment Variables
    4. Interactive Shell Settings
    5. tcsh's GNU-like ls Replacement
    6. My Standard Shell Aliases
    7. The Prompt
  2. OS-Specific
    1. By-Name Process Killing
    2. Solaris
    3. File System Stats (df)
  3. Advanced Setup
    1. Administration
    2. Java datasize
    3. Hooks/Events
    4. Keys
  4. Auto-Completion
    1. Miscellaneous
    2. Host-Based (DNS or Static)
      1. ~/.tcsh/hosts-pre (EXAMPLE)
      2. cronjob - DNS axfr based [host]
      3. cronjob - pingscan and reverse DNS based [nmap]
      4. ~/.tcshrc
    3. dpkg/apt-get/apt-cache
      1. cronjob - update package lists
      2. ~/.tcshrc or ~/.login
    4. Filename
  5. Misc
    1. Example Files

1.1 A Righteous umask

Start off with a decent umask. 22 (0666 & ~022 = 0644) creates files with rw-r--r-- permissions.

umask 22

1.2 A Flexible PATH/MANPATH

To set up a good PATH that will work on most any system, you will use wildcards and a little creativity. If java (or similar) is in an odd place (such as /usr/pkg/java/bin or /usr/local/java/bin), just link that base/prefix under /opt.

set path = (/usr/man /usr/*/man /opt/*/man)
setenv MANPATH "$PATH"
set path = (/opt/*/{,s}bin /usr/*/{,s}bin /{,s}bin /usr/{,s}bin /usr/games /usr/ucb)
set path = ($path ~/arch/`uname -s`/bin/`uname -m` ~/bin ~/arch/neutral/bin)

1.3 Standard Environment Variables

This will set the standard editor to zile (..Is Like Emacs), pager to the last found of more, less, most. Then set the default blocksize (display) to megabytes and tell less to not cause headaches with beeping at EOF.

setenv EDITOR zile    # or vi, emacs
where more >/dev/null && setenv PAGER more
where less >/dev/null && setenv PAGER less
where most >/dev/null && setenv PAGER most
setenv LESS "-q"
setenv HOSTV `uname -s`

1.4 Interactive Shell Settings

These are all useful options that most people will want to set. tcsh will notify you of mail in your Maildir, as well as print process load, abnormal exit value, and ambiguous autocompletion matches.

## interactive prompt conditional. ends much later on
if ($?prompt) then
set history = 256
set mail = (25 $HOME/Maildir/cur)
set noding
set autolist
set listlinks
set time = (1 "%U user, %S kernel, %E world, %P%% cpu")
set visiblebell
set printexitvalue

1.5 tcsh's GNU-like ls Replacement

tcsh has a built-in lightweight ls function called ls-F. The pseudo-program supports colors and can be used so that GNU (Linux) and non-GNU OS's always have similarly behaving ls output.

setenv LS_COLORS 'no=00:fi=00:di=01;37:ln=01;36:pi=40;33:so=40;33:bd=40;33:cd=40;33:ex=01;32:*.sh=01;32:*.pl=01;32:*.bin=01;32:*.class=01;32:*.php=01;32:*.php3=01;32:*.js=01;32:*.tar=01;31:*.tgz=01;31:*.rpm=01;31:*.deb=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.rar=01;31:*.pkg=01;31:*.jpg=35:*.jpeg=35:*.gif=35:*.png=35:*.bmp=35:*.xbm=35:*.xpm=35:*.pm=35:*.xwd=35:*.pic=35:*.mp3=35:*.xcf=35:*.rm=35:*.avi=35:*.flac=35:*.ogg=35:*.mpg=35:*.wav=35:*.mpeg=35:*.ps=34:*.pdf=34:*.rtf=34:*.html=34:*.htm=34:*.xls=34:*.gnumeric=34:*.abw=34:*.tex=34:*.txt=34:*.doc=34:*.c=33:*.h=33:*.java=33:*.cc=33:*.hh=33:'
set color = (ls-F)
alias ls "ls-F"

1.6 My Standard Shell Aliases

These aliases are optional, but often very useful. setx6 (Solaris to Linux), setv (~vt100 to Anything), and setp (Windows to Linux) are useful when doing ssh/telnet work back and forth between platforms.

alias asend "ls -FAlR | sort -n +4"
alias hist "history 15"
alias sets "setenv TERM sun"
alias setp "setenv TERM pcansi"
alias setx "setenv TERM xterm"
alias setx6 "setenv TERM xterm-r6"
alias setv "setenv TERM vt100"
alias so "source"

1.7 The Prompt

The following example prompt setting will end up with a prompt similar to this:

( inittab@idlefortress:~ ; dev=pts/22 ; time=6:00:09 ; num=13 )
set prompt = "\n%S(%s %U%n%u@%B%m%b:%~ ; dev=%l ; time=%P ; num=%h %S)%s\n %#%L "

2.1 By-Name Process Killing

Something rarely standardized, even among BSDs.. Here you can cause "nkill" to be an alias of an apropriate process hit-man.

if ("$HOSTV" == "OpenBSD") then
  alias nkill "zap -f"
else if ("$HOSTV" == "FreeBSD" || "$HOSTV" == "Linux") then
  alias nkill "killall"
else if ("$HOSTV" == "NetBSD" || "$HOSTV" == "SunOS") then
  alias nkill "pkill"

2.2 Solaris

BSD users may wish to set aliases on Solaris for ping, ps, df, and du. It's better to do this than to put /usr/ucb before /usr/bin and /usr/ccs/bin in your PATH because that could cause several problems during compilation processes.

if ("$HOSTV" == "SunOS") then
  alias ping "ping -s"
  alias ps /usr/ucb/ps
  alias df /usr/ucb/df
  alias du /usr/ucb/du

2.3 File System Stats (df)

You could also set an alias to use specific parameters for df on various operating systems.

#netbsd -a -k 
#openbsd, freebsd, sunos -a -h
#linux/gnu -a -h -T
# check OpenBSD's "-a" option
if ("$HOSTV" == "Linux") then
  alias df "df -haT"
else if ("$HOSTV" == "NetBSD") then
  alias df "df -a"
  alias df "df -ha"

3.1 Administration

These things all must run as root. You must configure sudo to use them.

alias ethereal "sudo -H ethereal"
alias port_install "sudo make install && sudo make clean"
alias rdate "sudo rdate"
alias cdrecord "sudo cdrecord"
alias reboot "sudo reboot"
alias halt "sudo halt"
alias shutdown "sudo shutdown"

if ("$HOSTV" =~ BSD) then
  alias pkg_add "sudo pkg_add"

if ("$HOSTV" == "FreeBSD") then
  set ports = `cd /usr/ports; /bin/ls *`
  complete pkg_add 'n/-r/$ports/'

if ("$HOSTV" == "NetBSD") then
  set ports = `cd /usr/pkgsrc; /bin/ls *`
  complete fetch 'p/1/$ports/'

3.2 Java datasize

If you will be using Java 1.5 or some versions of 1.4, you may need to increase the datasize limit.

limit datasize 262144

3.3 Hooks/Events

You may wish to have a custom X11 window title on your terminals, and you will most certainly want to keep an accurate binary image of the PATH.

# precmd = before prompt
# postcmd = before exec
switch ($TERM)
case "rxvt":
case "dtterm":
case "xterm*":
  alias precmd 'printf "\033]0;${HOST}:$cwd\007"'

## cause new programs to be recognized after installed
alias postcmd "rehash"

3.4 Keys

Set up standard keys. These include: Home, End, Backspace, Delete, Up, Down, etc..

bindkey -e
bindkey "^W" backward-delete-word
# bindkey "^H" backward-delete-char
# bindkey "^?" delete-char
## vt100 sends ^? for backspace key and ^[[3~ for delete key
bindkey "^?" backward-delete-char
bindkey "^[[3~" delete-char
bindkey "^[[28~" run-help
bindkey "^[[1~" beginning-of-line
bindkey "^[[4~" end-of-line
bindkey -k up history-search-backward
bindkey -k down history-search-forward

stty sane
stty echoe
# stty erase "^H"
stty erase "^?"

4.1 Miscellaneous

Sometimes you want programs to autocomplete other programs, processes, directories, or even just program flags/options if used often enough.

## shell
complete {cd,pushd,popd} 'p/1/d/'
complete {unset,print}env 'n/*/e/'
complete unalias 'n/*/a/'
complete unset 'n/*/s/'
complete uncomplete 'n/*/X/'

## misc
complete find 'p/1/d/' 'c/-/(name size mtime perm type print print0 user)/'
complete kill 'c/-/S/' 'c/%/j/'
complete {pkill,man,killall,exec,sudo,fakeroot} 'p/1/c/'
complete wine 'p/*/f:*.exe/'

# screensaver causes problems (ut and mplayer)
alias mplayer "mplayer -stop-xscreensaver"

## x11 & graphics
complete xrdb 'c/-/(load merge query)/'
complete xwd 'c/-/(root out nobdrs display frame)/'
complete xmove 'c/-/(server port)/'
complete xmovectrl 'c/-/(quit setdefaultserver move moveall list)/'

4.2 Host-Based (DNS or Static)

You may have hosts configured dynamically or statically in your DNS servers that which you frequently connect. You can set up a cron job to make a list of hosts to be used for autocompletion. tcsh then only has to read the file and complete accordingly.

If you have a very, very short list of hosts and aliases on your network, then you could just put all the hosts in ~/.tcsh/hosts or even directly in the ~/.tcshrc file. Otherwise, it is convenient to be able to tab-complete ftp, ssh, telnet, links, etc based on DNS. To use this cronjob, create a file named ~/.tcsh/hosts-pre [4.2.1] either empty or with a list of hosts on external networks to be added that will not be discovered by the cronjob [4.2.2/host-axfr or 4.2.3/nmap]. After setting up the crontab entry, you can set up auto completion macros [4.2.4] for any application that accepts a hostname as an argument.

[4.2.1] ~/.tcsh/hosts-pre (EXAMPLE)

[4.2.2] cronjob - DNS axfr based [host]

This is one of many scripts you could use to accomplish this task. It requires that your cron server have AXFR privileges on your DNS servers. You could also use `host -l` instead of `host -t axfr` which will allow you to remove the three `grep -v` commands as well as the `sed` at the end. Only problem with `host -l` is that it will not pick up CNAME records, only A. This file is downloadable below.

for each in $DOMAINS; do
     host -t axfr $each | grep -v ';' | grep -v Trying | grep -v Received | awk '{print $1}' | sed 's/\.$//'
#    host -l $each | awk '{print $1}' ## when uncommented, comment above
) | sort | uniq > $HOSTS

[4.2.3] cronjob - pingscan and reverse DNS based [nmap]

This example uses nmap to ping your whole network and take a "snapshot" of it. nmap prints the DNS name acquired from reverse DNS, if found. Else, nmap just prints the IP. This is fine. This file is downloadable below.


nmap -sP $NET | grep -v -i nmap | awk '{print $2}'
) | sort > $HOSTS

[4.2.4] ~/.tcshrc

These are examples of hostname auto-completion for some very common networking utilities. Position-based (most) and Option-based (ssh, x2x, xhost) examples are shown. If you use links or lynx frequently, be weary of using that rule, as it will supercede filename completion. Expect an update.

set hosts = `cat ~/.tcsh/hosts`
complete nmap 'n@-e@`ifconfig -l`@' 'p/*/$hosts/'
complete finger 'c/*@/$hosts/' 'n/*/u/@'
complete ping 'p/*/$hosts/'
complete host 'p/*/$hosts/'
complete traceroute 'p/*/$hosts/'
complete {rlogin,slogin,ssh} 'c/-/"(l e X)"/' 'n/-l/u/' 'p/*/$hosts/'
complete telnet 'p/*/$hosts/'
complete rdate 'p/*/$hosts/'
complete ftp 'p/*/$hosts/'
complete {links,lynx} 'p/*/$hosts/'
complete xhost 'c/+/$hosts/'
complete x2x 'c/-/(to from east west)/' 'n/-{to,from}/$hosts/:/'

4.3 dpkg/apt-get/apt-cache

Debian users can cause tab-completion on apt-get, apt-cache and dpkg to complete to the current package states. This requires a cronjob [4.3.1] to run occaisionally as well as about 200kb of RAM per shell for the relevant environment variables [4.3.2].

[4.3.1] cronjob - update package lists

This file is downloadable below.

dpkg --get-selections | awk '{print $1}' >.tcsh/ipkg
apt-cache search '' | awk '{print $1}' >.tcsh/apkg

[4.3.2] ~/.tcshrc or ~/.login

if ( -f /etc/debian_version ) then
  alias apt-get "sudo apt-get"
  alias dpkg "sudo dpkg"
  alias alien "sudo alien"
  set ipackages = `cat .tcsh/ipkg`
  set apackages = `cat .tcsh/apkg`
  complete dpkg 'n/-L/$ipackages/' 'p/*/f:*.deb/'
  complete apt-cache 'n/{show,search,depends}/$apackages/' 'p/*/(show search pkgnames depends)/'
  complete apt-get 'n/{install,remove}/$apackages/' 'p/*/(update install remove upgrade dist-upgrade clean)/'

4.4 Filename

Often, it is nice to have tab-completion only complete on specific filename extensions or types for specific programs.

## multimedia
complete pngcrush 'p/*/f:*.png/'
complete {display,convert,gimp,qiv,gqview,xzgv} 'n/*/f:*.{jpg,jpeg,gif,bmp,tiff,pcx,pbm,pgm,ppm,xpm,pm,xwd,ps,eps,png}/'
complete xwud 'n/-in/f:*.xwd/'
complete xmms 'p/*/f:*.{mp3,flac,ogg}/'
complete mpg{123,321},madplay 'p/*/f:*.mp3/'
complete ogg123 'p/*/f:*.ogg/'

## documents
complete gv 'p/*/f:*.{ps,pdf}/'
complete xdvi 'p/*/f:*.dvi/'
complete {xpdf,acroread} 'p/*/f:*.pdf/'
complete {,pdf,ps}latex 'p/*/f:*.tex/'
complete html2ps 'p/*/f:*.{html,htm}/'
complete ps2pdf 'p/*/f:*.ps/'
complete pdf2ps 'p/*/f:*.pdf/'
complete dvi{pdf,ps} 'p/*/f:*.dvi/'
complete lpr 'n/*/f:*.{ps,txt}/'

## compression & archival
complete gunzip 'p/*/f:*.{gz,tgz}/'
complete uncompress 'p/*/f:*.{Z,z}/'
complete bunzip2 'p/*/f:*.{bz2,tb2}/'
complete unzip 'p/*/f:*.zip/'
complete unrar 'p/*/f:*.rar/'
#end conditional started at interactive prompt

5.1 Example Files

$ Last Modified: 2005-08-08 01:00 $