Summary
csh and tcsh are initialized by your ~/.cshrc file (~/.tcshrc for
tcsh, if it exists). These files are loaded every time you initialize a
new shell, be it to run a script or actually interact with your system.
Either way, you will be constantly using this configuration, so you want
it to work as well as possible.
The variables you're going to want to worry about with your cshrc:
- csh/tcsh settings - these are generally fairly consistent across
all platforms, but should be carefully considered for each person.
A few setting changes can make all the difference!
- Environment variables - these are generally set on a per-network
basis.
- PATH and MANPATH - these will vary by platform and network.
- Shell aliases - you will probably want a fair number of these to
just speed your work up.
This configuration tries to set things up hierarchically. Files are
loaded in this order:
- Load ~/.cshrc (or~/.tcshrc)
for the default configuration and to load other files.
- If we are running interactively:
- Load ~/.config/alias sets up general command
aliases.
- Based on the platform architecture, loads ~/.config/alias.PLATFORM
- Load ~/.config/alias.DOMAIN, where DOMAIN is the second element of
the hostname ('my.host.name' returns 'host').
- Load ~/.config/alias.MACHINE, where MACHINE is the first element of
the hostname ('my.host.name' returns 'my').
- Load cshrc.devel, which offers development-
specific cshrc commands.
- Load ~/.config/cshrc.DOMAIN, where DOMAIN is the second element of
the hostname ('my.host.name' returns 'host').
- Load ~/.config/cshrc.MACHINE, where MACHINE is the first element of
the hostname ('my.host.name' returns 'my').
- On login shells:
- Load ~/.login for login information.
- Load ~/.config/login.DOMAIN, where DOMAIN is the second element of
the hostname ('my.host.name' returns 'host').
- Load ~/.config/login.MACHINE, where MACHINE is the first element of
the hostname ('my.host.name' returns 'my').
One additional guidelines: you want things to load fast, so make sure
that you're setting as much as possible only when you're using it interactively
(if ($?prompt)). The below scripts follow this.
Files
Generic Files
These files are the ones that are linked into ~/.cshrc and ~/.tcshrc
directly, and are loaded across all platforms. You'll modify these to
match how you actually do business.
cshrc
Sets a few default variables, and then loads lots of sub-files.
set DEBUG=0 # Set to '1' to get some debugging info
set FILE="~/.config/cshrc"
set TEXT="Generic .cshrc directives"
set VERSION='$Id: cshrc 91 2008-07-17 18:08:44Z tskirvin $'
if ( $DEBUG == "1" ) echo "${FILE} (${TEXT}) v${VERSION}"
###############################################################################
### Default settings ##########################################################
###############################################################################
unset autologout # Why would I want to auto-logout?
unset ignoreeof # ^D should log us out, dammit!
# set coredumpsize=0 # Cores are size zero
umask 022 # Create files with permissions 755 by default
set notify # Reports change of status of background processes
set history=100 # Remember the last 100 commands
set filec # File completion for tcsh
set noclobber # Don't replace existing files with ">" redirection
unset savehist # History stuff doesn't do me much good
setenv HOSTNAME `uname -n | tr A-Z a-z` # Machine hostname
## Trying these out from Russ/Stanford
set cdpath = ( . ~ )
set fignore = ( \~ .o CVS )
###############################################################################
### Set the default paths #####################################################
###############################################################################
set path = ( /usr/bin /bin /usr/sbin /sbin );
setenv MANPATH "/usr/man:/usr/share/man";
# Basic path areas can be dealt with systematically
foreach loc ( local local64 )
if ( -d /usr/$loc/bin ) set path = ( /usr/$loc/bin $path );
if ( -d /usr/$loc/sbin ) set path = ( /usr/$loc/sbin $path );
if ( -d /usr/$loc/X/bin ) set path = ( /usr/$loc/X/bin $path );
if ( -d /usr/$loc/man ) setenv MANPATH /usr/$loc/man:${MANPATH}
if ( -d /usr/$loc/share/man ) setenv MANPATH /usr/$loc/share/man:${MANPATH}
if ( -d /usr/$loc/shared/man ) setenv MANPATH /usr/$loc/shared/man:${MANPATH}
end
foreach loc ( sweet pubsw )
if ( -d /usr/$loc/bin ) set path = ( $path /usr/$loc/bin );
if ( -d /usr/$loc/sbin ) set path = ( $path /usr/$loc/sbin );
if ( -d /usr/$loc/X/bin ) set path = ( $path /usr/$loc/X/bin );
if ( -d /usr/$loc/man ) setenv MANPATH ${MANPATH}:/usr/$loc/man
if ( -d /usr/$loc/share/man ) setenv MANPATH ${MANPATH}:/usr/$loc/share/man
if ( -d /usr/$loc/shared/man ) setenv MANPATH ${MANPATH}:/usr/$loc/shared/man
end
# Prefix to the path, in reverse order
foreach loc ( $HOME/bin $HOME/progs/bin $HOME/.config/bin \
$HOME/progs/bin/$HOSTNAME )
if (-d $loc ) set path = ( $loc $path );
end
if (-d $HOME/progs/man) setenv MANPATH $HOME/progs/man:${MANPATH}
if (-d $HOME/.config/man) setenv MANPATH $HOME/.config/man:${MANPATH}
if (-d /opt/condor/man) set path = ( $path /opt/condor/man );
# Append to the path, in order
if (-d /usr/ccs/bin) set path = ( $path /usr/ccs/bin );
if (-d /usr/ucb) set path = ( $path /usr/ucb );
if (-d /usr/kerberos/bin) set path = ( $path /usr/kerberos/bin );
if (-d /usr/bin/X11) set path = ( $path /usr/bin/X11 );
if (-d /usr/lib/news/bin) set path = ( $path /usr/lib/news/bin );
if (-d /opt/condor/bin) set path = ( $path /opt/condor/bin );
# Check the current directory; this may not be a good idea.
# set path = ( $path . );
###############################################################################
### Environment Variables #####################################################
###############################################################################
setenv USERNAME `whoami` # Username
setenv HOSTNAME `uname -n | tr A-Z a-z` # Machine hostname
setenv HOST `echo $HOSTNAME | sed 's/\..*$//'` # Short hostname
setenv DOMAIN `echo $HOSTNAME | awk -F. ' { print $2 } '` # Short domainname
setenv OSTYPE `uname` # Operating system type
setenv ARCH `uname -m` # Underlying architecture
setenv MAIL /var/mail/$USERNAME # Base mailbox
setenv PAGER less # Base pager
setenv NNTPSERVER news.stanford.edu # News server
setenv LYNX_CFG ~/.config/lynx.cfg # Personal lynx configuration
setenv EDITOR vi # Backup if we're in csh
setenv LESS -aciRMQX~z-2j2 # Pager options make it better
# setenv LC_CTYPE en_US.ISO-8859-1 # For best viewing in mutt
## Trying these out from Russ/Stanford as well
setenv LANG en_US.UTF-8
setenv LC_ALL en_US.UTF-8
setenv LC_COLLATE C
setenv GREP_COLOR 36
###############################################################################
### OS-specific settings ######################################################
###############################################################################
## Set the OSHUMAN value, to be used when switching on architecture type
setenv OSHUMAN `echo ${OSTYPE} | tr A-Z a-z`
if ("${OSHUMAN}" == "sunos") then
setenv OSHUMAN "solaris"
else if ("${OSHUMAN}" == "SunOS") then
setenv OSHUMAN "solaris"
else if ("${OSHUMAN}" == "hp-ux") then
setenv OSHUMAN "hpux"
else if ("${OSHUMAN}" == "irix64") then
setenv OSHUMAN "irix"
else if ("${OSHUMAN}" == "osf1") then
setenv OSHUMAN "tru64"
else if ("${OSHUMAN}" == "darwin") then
setenv OSHUMAN "macosx"
endif
## Load the appropriate cshrc file, by architecture
if (-f $HOME/.config/cshrc.$OSHUMAN) source ~/.config/cshrc.$OSHUMAN
###############################################################################
### Additional Configuration ##################################################
###############################################################################
set MACHINE="${DOMAIN}.${HOST}"
if ($?prompt) then
set prompt="%m %~%# " # Prompt is of the "alpha ~> " format
if (-e $HOME/.config/alias) source ~/.config/alias
if (-e $HOME/.config/alias.${DOMAIN}) source ~/.config/alias.${DOMAIN}
if (-e $HOME/.config/alias.${MACHINE}) source ~/.config/alias.${MACHINE}
endif
if (-e $HOME/.config/cshrc.news) source ~/.config/cshrc.news
if (-e $HOME/.config/cshrc.devel) source ~/.config/cshrc.devel
if (-e $HOME/.config/cshrc.${DOMAIN}) source ~/.config/cshrc.${DOMAIN}
if (-e $HOME/.config/cshrc.${MACHINE}) source ~/.config/cshrc.${MACHINE}
unset MACHINE
###############################################################################
### Completions ###############################################################
###############################################################################
if ($?prompt) then
if ( $DEBUG == "1" ) echo "Loading completions ($HOME/.config/completions*)"
if (-e $HOME/.config/completions) source ~/.config/completions
if (-e $HOME/.config/completions.local) source ~/.config/completions.local
if (-e $HOME/.config/comphosts) then
set comp_host_names = (`cat ~/.config/comphosts`)
endif
if (-e $HOME/.config/cshrc.gnupg) source ~/.config/cshrc.gnupg
endif
###############################################################################
### Terminal Configuration ####################################################
###############################################################################
## Trying this out, from Stanford
if ($?prompt) then
if ( $DEBUG == "1" ) echo "Configuring terminal"
# Disable needless delays for special characters.
stty cr0 nl0 tab0 ff0 bs0
# Make sure we have sane special character bindings.
stty intr '^C' erase '^?' kill '^U' quit '^\'
#'# for sh-mode
# Standard terminal setup (this should be system independent).
(stty >/dev/null) |& grep echoctl >& /dev/null
if ($status == 0) stty echoctl ixany -istrip
(stty >/dev/null) |& grep echoke >& /dev/null
if ($status == 0) stty echoke
endif
###############################################################################
### tcsh Configuration ########################################################
###############################################################################
if ($?tcsh) then
## Key Bindings
bindkey -v
bindkey ^R i-search-fwd
bindkey ^F i-search-back
## From Stanford/Russ config; try them out!
set autolist = ambiguous
set listmax = 100
set nobeep
set pushdsilent
set pushdtohome
set symlinks = ignore
set pushdsilent
set pushdtohome
set symlinks=ignore
## This has to go here so that 'which' works as a command in csh.
if ($?prompt) then
## Default editor should be vim if possible, otherwise vi
if ( -x `which vim` ) then
setenv EDITOR `which vim`
else
setenv EDITOR vi
endif
endif
endif
Download
tcshrc
Generally just loads the .cshrc, but makes any additional changes that
tcsh supports but not csh.
source ~/.cshrc
## Key Bindings
bindkey -v
bindkey ^R i-search-fwd
bindkey ^F i-search-back
## From Stanford/Russ config; try them out!
set autolist = ambiguous
set listmax = 100
set nobeep
set pushdsilent
set pushdtohome
set symlinks = ignore
set pushdsilent
set pushdtohome
set symlinks=ignore
## This has to go here so that 'which' works as a command in csh.
if ($?prompt) then
## Default editor should be vim if possible, otherwise vi
if ( -x `which vim` ) then
setenv EDITOR `which vim`
else
setenv EDITOR vi
endif
endif
Download
login
Loaded only when you actually log in; follows the same general
principles, though.
set FILE="~/.config/login"
set TEXT="Generic .login directives"
set VERSION=0.1
if ( $DEBUG == "1" ) echo "${FILE} (${TEXT}) v${VERSION}"
# Print message-of-the-day
if (-e $HOME/.config/motd) cat $HOME/.config/motd
if (-e $HOME/.config/motd.${DOMAIN}) cat $HOME/.config/motd.${DOMAIN}
###############################################################################
### Additional Configuration ##################################################
###############################################################################
set MACHINE="${DOMAIN}.${HOST}"
if (-e $HOME/.config/login.${DOMAIN}) source ~/.config/login.${DOMAIN}
if (-e $HOME/.config/login.${MACHINE}) source ~/.config/login.${MACHINE}
unset MACHINE
Download
alias
Command aliases that are used everywhere. Further refinement is
possible in network- or platform-specific alias files.
set FILE="~/.config/alias" # $Id: alias 88 2008-07-11 20:44:19Z tskirvin $
set TEXT="generic csh/tcsh aliases"
set VERSION=0.1
if ( $DEBUG == "1" ) echo "${FILE} (${TEXT}) v${VERSION}"
###############################################################################
### Basic Aliases #############################################################
###############################################################################
alias f 'finger'
alias more 'less'
## Fixing typos
alias l 'ls'
alias sl 'ls'
alias mroe 'more'
## Shorter program names for regularly used stuff
alias bmark 'lynx ~/.lynx.html'
alias lsd 'ls -la grep "`date +%b\ %d`"'
alias m 'mutt'
alias mf 'mutt -f'
alias my 'mutt -y'
alias mp3 'mpg123 -b2048 -v'
alias n 'nn'
alias sa-spam 'sa-learn --showdots --mbox --spam --no-sync'
alias sa-ham 'sa-learn --showdots --mbox --ham --no-sync'
## Terminal aliases
# stty intr ^C erase ^? kill ^U # Default values
alias vt100 'set term=vt100'
alias herase 'stty erase ^\?'
alias 'stty erase ^\?'
alias serase 'stty erase ^H'
alias 'stty erase ^H'
## Use more advanced programs instead of older ones, if available
if (-x /usr/bin/nph || -x /usr/local/bin/nph) alias ph nph -r
if (-x `which vim`) alias vi vim
## Killfile-specific CVS stuff?
alias kfcvs 'setenv CVSROOT :ext:tskirvin@killfile.org:/home/tskirvin/cvs'
alias veri-cvs 'setenv CVSROOT :ext:tskirvin@mod.killfile.org:/home/tskirvin/cvs-verimod'
alias get-config 'svn checkout svn+ssh://cvs.killfile.org/home/svn/config/trunk .config'
###############################################################################
### Russ/Stanford Aliases #####################################################
###############################################################################
## Testing these out; will I use any of them?
alias ctar 'tar cfvz \!:1.tar.gz \!:2*'
alias vtar 'tar tfvz \!* | more'
alias xtar 'tar xfvz'
alias cbtar 'tar cfvj \!:1.tar.bz2 \!:2*'
alias vbtar 'tar tfvj \!* | more'
alias xbtar 'tar xfvj'
# Documentation viewing. Running Perl docs through nroff is too slow.
alias nman 'nroff -man \!* | more -s'
alias perldoc 'perldoc -t'
# Building patch files and finding changed files.
alias buildpatch \
"find \!:1 -name \*.orig -print | sed -e 's/.orig"'$'"//'" \
"| xargs -i# diff -u #.orig # \!:2*"
alias fdiff 'diff -u \!:1{.orig,} \!:2*'
alias findorig 'find \!* -name \*.orig -print'
alias orig 'cp -p \!:1 \!:1.orig && chmod u+w \!:1'
alias unorig 'mv \!:1.orig \!:1'
# C dependencies.
alias cdepend 'gcc -E -MM \!:*'
# Quick find.
alias fn 'find -name \!:1 -print \!:2*'
# Emacs byte compilation.
alias bytecc 'emacs -q -batch -f batch-byte-compile'
# InterNIC host lookup.
alias arin 'whois -h whois.arin.net'
alias internic 'whois -h rs.internic.net'
alias nic 'whois -h whois.geektools.com'
# Quick time conversion.
alias localtime perl -e \'print scalar localtime \!:1, \"\\n\"\'
# Quick string length check.
alias strlen perl -e \'print length '($ARGV[0])', \"\\n\"\'
# Used to create dated working directories and manipulate them.
alias today 'date +%Y%m%d'
alias cdt 'cd \!:1/`today`'
alias mktoday 'mkdir `today`'
# Finding locations in files.
alias wherein "awk '{ i++ } /\!:1/ { print i }' \!:2* && wc -l \!:2*"
###############################################################################
### Log File Helper Scripts ###################################################
###############################################################################
## Mail logs, generated by procmail
if (-e $HOME/mail/daily) then
alias tf "tail -20 ~/mail/daily"
alias ttf "tail -f ~/mail/daily"
alias tff "less -n +G ~/mail/daily"
else
alias tf echo "Not supported on this system"
alias ttf "ssh killfile.org tail -f ~/mail/daily"
alias tff echo "Not supported on this system"
endif
## Web logs, generated by apache
if (-e $HOME/logs/web.daily) then
alias ta 'tail -10 ~/logs/web.daily'
alias tta 'tail -f ~/logs/web.daily'
alias taa 'less -n +G ~/logs/web.daily'
alias taaj 'cat ~/logs/web.daily | grep -v -i jpg | grep -v -i gif | less -n +G'
alias tamf 'tail -f ~/logs/web.daily | grep tskirvin'
alias tam 'cat ~/logs/web.daily | grep tskirvin | less -n +G'
alias te 'tail -10 ~/logs/error.daily'
alias tte 'tail -f ~/logs/error.daily'
alias ttee 'less -n +G ~/logs/error.daily'
endif
###############################################################################
### Basic Scripts #############################################################
###############################################################################
alias dus 'du -ks * | sort -rn'
alias everysec 'perl -e "while (1) { system(@ARGV); sleep 1 }"'
# alias rot13 'tr A-Za-z N-ZA-Mn-za-m'
alias motd ~/.config/bin/motd
###############################################################################
### Default Configurations ####################################################
###############################################################################
alias xv 'xv -drift 0 0'
# alias gpg 'gpg --default-key 0x0C2DD21D'
alias scp 'scp -C'
###############################################################################
### Additional Configuration ##################################################
###############################################################################
## Load SSH directives from separate file
if (-e $HOME/.config/alias.systems) source ~/.config/alias.systems
## Developer aliases
if (-e $HOME/.config/alias.devel) source ~/.config/alias.devel
## Developer aliases
if (-e $HOME/.config/alias.color) source ~/.config/alias.color
## Load additional aliases, by architecture
if (-f $HOME/.config/alias.$OSHUMAN) source ~/.config/alias.$OSHUMAN
Download
cshrc.devel
Used to set things up for development.
set FILE="~/.config/cshrc.devel"
set TEXT="Development .cshrc directives"
set VERSION='$Id: cshrc.devel 87 2008-07-02 15:28:00Z tskirvin $'
if ( $DEBUG == "1" ) echo "${FILE} (${TEXT}) v${VERSION}"
###############################################################################
### Encap and build configuration stuff #######################################
###############################################################################
setenv ENCAP_CONTACT '"Tim Skirvin" '
#setenv CPPFLAGS "-I/usr/local/include"
#setenv LDFLAGS "-L/usr/local/lib -R/usr/local/lib"
setenv MKENCAP_BUILD_TREE /tmp/%p
setenv MKENCAP_DOWNLOAD_DIR ${HOME}/src
setenv LD_RUN_PATH /usr/local/lib:/usr/lib:/lib
if (-x /usr/local/bin/m4) setenv MKENCAP_M4_COMMAND /usr/local/bin/m4
## Mostly useful on the Suns
if (-x /usr/sfw/lib) setenv LD_RUN_PATH /usr/sfw/lib:${LD_RUN_PATH}
# if (-x /usr/sfw/lib) setenv LDFLAGS "-L/usr/sfw/lib -R/usr/sfw/lib ${LDFLAGS}"
# if (-x /usr/ucblib) setenv LDFLAGS "${LDFLAGS} -L/usr/ucblib -R/usr/ucblib"
# if (-x /usr/sfw/include) setenv CPPFLAGS "-I/usr/sfw/include ${CPPFLAGS}"
###############################################################################
### CVS Configuration #########################################################
###############################################################################
#setenv CVS_RSH ssh
#setenv CVSROOT :pserver:tskirvin@cvs.ks.uiuc.edu:/sysadmin
###############################################################################
### Debian Package Build #####################################################
###############################################################################
setenv DEBFULLNAME "Tim Skirvin"
setenv DEBEMAIL 'tskirvin@killfile.org'
setenv DEBSIGN_KEYID "0C2EE21D"
###############################################################################
### Additional Aliases ########################################################
###############################################################################
alias develop unsetenv LD_LIBRARY_PATH
Download
Platform-Specific Files
These files modify the environment based on the platform you're
running on - adding additional PATHs for a Linux or Solaris system, for
instance. Rather than loading them all individually, you can download
them per-platform from this table:
Network-Specific Files
These files modify aliases or environment variables on a per-network
or -system level. I'm not going to distribute these at this point.
Other Files
completions
The 'completions' code is actually a slightly modified version of
Debian's /usr/share/doc/tcsh/examples/complete.gz; it's not
worth listing in its entirety here, but can be downloaded here.
comphosts
This is a file containing hostnames, one per line, that you want to
be able to match with command-line completion.