User:Mjb/tcsh configuration files
From Offset
< User:Mjb
Jump to navigationJump to searchHere are the tcsh shell configuration files I use. I try to keep them compatible with csh but have not fully tested them there.
.login
# csh and tcsh .login # # This is for things that only need to be run once, at login. # # See .cshrc for both login and non-login shell settings, including # things to do if you are changing shells after login. # (tcsh only) warn if current terminal type isn't in termcap or terminfo # if ($?tcsh) then if ( ! { (termname >& /dev/null) } ) then echo "Terminal type '${term}' is unrecognized on this system." echo " If you want to set a different type, use 'setenv <foo>'." echo " If you want to keep this type but use another's capabilities, use 'tset <foo>'." echo " Use 'termname <foo>' to see if foo is recognized on this system." echo endif endif # backspace and delete need to work the way I expect them to # stty sane # see who's logged in # echo 'Users online:' users # In xterm-based terminals, set the window title before each prompt is displayed. # This is here instead of in .cshrc because this particular title uses the initial # login date & time for a particular host. If it were in .cshrc, it would update # the login time each time an interactive csh or tcsh subshell is started. # if ( $?prompt && $TERM:s/-/./:r == "xterm" ) then alias settitle printf '"\033]2;\!*\a\033]1;\!*\a\033]0;\!*\a"' alias precmd settitle $HOST · logged in since `sh -c 'date -j "+%Y-%m-%d %T" 2> /dev/null || date "+%Y-%m-%d %T"'` endif # Some apps, like 'less' without the -X flag, like to switch to and from a # separate screen buffer (actually cursor-addressing mode rather than # memory-addressing mode). This capability is not on all terminals, and some # terminals wipe the original buffer when switching back to it. These # behaviors and their effects on terminal emulator scrollback buffers can be # confusing for users. # # The switching is achieved by the ANSI code sequences assigned to terminal # capabilities 'ti' & 'te' (termcap) or 'smcup' & 'rmcup' (terminfo). It can # be disabled via a custom termcap or terminfo entry. Both work the same, # amending an existing entry to disable the capabilities via '@' suffixes. # # Here we do it for xterm-256color: # if (-f /etc/termcap) then # TERMCAP is the custom termcap entry itself setenv TERMCAP ${TERM}:ti@:te@:tc=${TERM} else if (-d /etc/terminfo && -X tic) then # TERMINFO is a directory of tic(1)-compiled terminfo sources setenv TERMINFO ~/.terminfo setenv _TERMINFO_SOURCE ~/.terminfo-xterm-256color.src echo "xterm-256color, smcup@, rmcup@, use=xterm-256color," >! ${_TERMINFO_SOURCE} tic ${_TERMINFO_SOURCE} unsetenv _TERMINFO_SOURCE else echo "Could not disable separate screen buffer." endif # warn if terminal size is undefined # if ( $?prompt && { ( stty -a | grep columns | egrep -q '0 rows; 0 columns|rows 0; columns 0' ) } ) then echo "Terminal size is undefined; please 'stty rows # cols #' appropriately." endif if ( -f ~/.login.local ) source ~/.login.local
.cshrc
# mjb's .cshrc # # Contains shell settings for csh and tcsh. # On FreeBSD 4.1 and up, csh doesn't exist; it's a hard link to tcsh. # # Order of processing (login shells): # 1. /etc/csh.cshrc # 2. /etc/csh.login # 3. ~/.tcshrc (if exists), else ~/.cshrc (this file) # 4. file in 'histfile' shell variable (if exists), else ~/.history # 5. ~/.login # 6. file in 'dirsfile' shell variable (if exists), else ~/.cshdirs # # Order of processing (non-login shells): # 1. /etc/csh.cshrc # 2. ~/.tcshrc (if exists), else ~/.cshrc (this file) # # I use this .cshrc on multiple hosts, so it only contains settings # common to all of them. At the end, it runs ~/.cshrc.local, which # contains host-specific settings. # ############################################################################## # Settings for all csh/cshrc instances running under my userid # ### umask sets a mask for the default file permissions umask 022 # unset group & others write, i.e. rw-r--r-- or rwxr-xr-x ### character encoding and localization preference setenv LANG en_US.UTF-8 # another option is en_US.ISO8859-1 ### misc program options setenv BLOCKSIZE 1k # for /bin/ls setenv GZIP '-9' # for /usr/bin/gzip setenv BZIP2 '-9' # for /usr/bin/bzip2 ############################################################################## # Settings for all csh/cshrc interactive shells, which includes: # * login shell (the shell instance you get at login) # * non-login shells (any shell instances you invoke after login) # # This does not include shells referenced by script shebang lines unless they # use -i, which would be very unusual. We could also use ($?loginsh) to test # for -l or login shell, but there's not really anything that we would want # to be exclusive to a login shell that we don't already do in ~/.login. # if ($?prompt) then ### improved key bindings bindkey "^W" backward-delete-word # ctrl + W bindkey -k up history-search-backward # up arrow bindkey -k down history-search-forward # down arrow bindkey '^[[1;5D' backward-word # ctrl + left arrow bindkey '^[[1;5C' forward-word # ctrl + right arrow bindkey "\e[1~" beginning-of-line # home bindkey "\e[3~" delete-char # delete bindkey "\e[4~" end-of-line # end ### ctrl-D at prompt won't logout set ignoreeof ### tab completion set autolist ### complete filenames in csh (automatic for tcsh) set filec ### beep only if no matches in filename completion attempt set matchbeep = nomatch ### default typing mode (insert or overwrite) set inputmode = insert ### save 1000 lines of history set history = 1000 ### restrict output redirection to not destroy existing files set noclobber ### aliases could be set in .login, but here is better (esp. for 'su') if (-f ~/.alias) source ~/.alias ### ask for confirmation before doing 'rm *' set rmstar ### CVS related setenv CVS_RSH ssh setenv CVSEDITOR nano ### IRC related setenv IRCNICK mjb ### my favorite editors if (-x /usr/local/bin/nano) then setenv EDITOR /usr/local/bin/nano setenv VISUAL /usr/local/bin/nano else if (-x /usr/local/bin/pico) then setenv EDITOR /usr/local/bin/pico setenv VISUAL /usr/local/bin/pico endif ### my favorite pagers if (-X less) then setenv PAGER less setenv LESS '--quit-at-eof --quit-if-one-screen --hilite-search --ignore-case --LONG-PROMPT --quiet --tabs=4 --tilde' setenv LESSHISTFILE /dev/null else setenv PAGER more endif ### plain prompts; usually overridden below if ($?tcsh) then set prompt = "[%m] %t %c %# " set symlinks = chase # in prompt, use real directory name, not symlink set noding # in prompt, don't say "DING!" at the top of the hour else set mch = `hostname -s` set prompt = "${mch:q}: {\!} % " endif ### in tcsh, allow 'echo' builtin to recognize SysV-style escape sequences set echo_style = both ### if terminal supports ANSI text formatting reset (of bold, underline, etc.) # echotc is tcsh-only, so we use tput instead if ({ ( tput me >& /dev/null || tput sgr0 >& /dev/null ) }) then # make ${E} be escape plus '[' if ($?tcsh) then # assumes echo_style is 'both' set E = `echo -n "\e["` else if ({ filetest -X printf }) then set E = `printf '\033['` else set E = `echo -n 'E[' | tr E \\033` endif ### if terminal supports setting ANSI foreground color (thus, ANSI color codes in general) if ({ ( tput AF 37 >& /dev/null || tput setaf 37 >& /dev/null ) }) then if ($?tcsh) then ### use fancy tcsh prompt with bold, underline, and color set prompt = "%{\033[0m\033[1;30m%}%U[%m] %t%u %B%{\033[33m%}%c%b %# " ### enable color output for NLS messages set colorcat ### enable color output for ls-F (shell builtin) ### without args, ls-F calls /bin/ls -F and colorizes as per LS_COLORS, below ### with args, ls-F calls /bin/ls -F, plus /bin/ls's color flag: ### on most systems, it's --color=auto (as used by GNU ls) ### on BSD, it's -G (colors as per LSCOLORS, below) ### on BSD, CLICOLOR being set forces -G behavior even if 'color' is unset! set color ### ANSI color codes for ls-F when called without arguments ### (with arguments, regular /bin/ls -G handling applies!) if (-f ~/.colors) setenv LS_COLORS `awk '! /^#|^$|\t/ {printf $1"="$2":"}' ~/.colors` endif ### enable color output for BSD /bin/ls (has same effect as /bin/ls -G) ### CLICOLOR_FORCE is needed to keep color when piping ls output to 'less' ### CLICOLOR_FORCE may interfere with programs that parse ls output! setenv CLICOLOR setenv CLICOLOR_FORCE ### color codes for BSD /bin/ls with CLICOLOR set or with -G setenv LSCOLORS GxDxBeCbCxExhxfxgxfxgx ### enable color in GNU grep setenv GREP_OPTIONS --color=auto ### set temporary variables for ANSI text formatting with color ### ';5;nnn' assumes extended color is available. set ANSI_black = "${E}0;30m" set ANSI_red = "${E}0;31m" set ANSI_green = "${E}0;32m" set ANSI_yellow = "${E}0;33m" set ANSI_blue = "${E}0;34m" set ANSI_magenta = "${E}0;35m" set ANSI_cyan = "${E}0;36m" set ANSI_white = "${E}0;37m" set ANSI_brightblack = "${E}1;30m" set ANSI_brightred = "${E}1;31m" set ANSI_brightgreen = "${E}1;32m" set ANSI_brightyellow = "${E}1;33m" set ANSI_brightblue = "${E}1;34m" set ANSI_brightmagenta = "${E}1;35m" set ANSI_brightcyan = "${E}1;36m" set ANSI_brightwhite = "${E}1;37m" set ANSI_defaultcolor = "${E}39m" set ANSI_reset = "${E}0m" if ({ (termname | fgrep -q 256color) }) then set ANSI_bold = "${E}1;38;5;74m" set ANSI_underline_on = "${E}4m${E}38;5;146m" set ANSI_standout_on = "${E}48;5;52m${E}38;5;197m" else set ANSI_bold = "${ANSI_brightcyan}" set ANSI_underline_on = "${E}4m${ANSI_magenta}" set ANSI_standout_on = "${E}41m${ANSI_brightyellow}" endif set ANSI_underline_off = "${E}24m${ANSI_defaultcolor}" set ANSI_standout_off = "${E}49m${ANSI_defaultcolor}" set ANSI_dim = "${E}2m" set ANSI_blink = "${E}5m" set ANSI_reverse = "${E}7m" set DIFF_plain_text = "${ANSI_brightblack}" set DIFF_file_old = "${ANSI_cyan}" set DIFF_file_new = "${ANSI_yellow}" set DIFF_added = "${ANSI_brightblue}" set DIFF_removed = "${ANSI_brightred}" set DIFF_changed = "${ANSI_blue}" set DIFF_diffstuff = "${ANSI_magenta}" else ### use fancy tcsh prompt with bold & underline but without color if ($?tcsh) set prompt = "%U[%m] %t%u %B%c%b %# " ### set temporary variables for ANSI text formatting without color set ANSI_reset = "${E}0m" set ANSI_bold = "${E}1m" set ANSI_dim = "${E}2m" set ANSI_blink = "${E}5m" set ANSI_reverse = "${E}7m" set ANSI_underline_on = "${E}4m" set ANSI_underline_off = "${E}24m" set ANSI_standout_on = "${E}48m" set ANSI_standout_off = "${E}49m" # untested set DIFF_plain_text = "${ANSI_reset}" set DIFF_file_old = "${ANSI_dim}" set DIFF_file_new = "${ANSI_bold}" set DIFF_added = "" set DIFF_removed = "" set DIFF_changed = "" set DIFF_diffstuff = "${ANSI_standout_on}" endif ### customizing 'less' makes man pages pretty if ( $?LESS ) then setenv LESS "${LESS} --RAW-CONTROL-CHARS" setenv LESS_TERMCAP_me "${ANSI_reset}" if ({ ( tput mb >& /dev/null || tput blink >& /dev/null ) }) setenv LESS_TERMCAP_mb "${ANSI_blink}" if ({ ( tput md >& /dev/null || tput bold >& /dev/null ) }) setenv LESS_TERMCAP_md "${ANSI_bold}" if ({ ( tput mh >& /dev/null || tput dim >& /dev/null ) }) setenv LESS_TERMCAP_mh "${ANSI_dim}" if ({ ( tput mr >& /dev/null || tput rev >& /dev/null ) }) setenv LESS_TERMCAP_mr "${ANSI_reverse}" if ({ ( tput us >& /dev/null || tput smul >& /dev/null ) }) setenv LESS_TERMCAP_us "${ANSI_underline_on}" && setenv LESS_TERMCAP_ue "${ANSI_underline_off}" if ({ ( tput so >& /dev/null || tput smso >& /dev/null ) }) setenv LESS_TERMCAP_so "${ANSI_standout_on}" && setenv LESS_TERMCAP_se "${ANSI_standout_off}" else setenv LESS "--RAW-CONTROL-CHARS" endif ### create aliases for colored diffs ### diff-n, diff-u, diff-c for normal, unified, context set diffn_exprs = '-E -e "s/^> /'"${DIFF_file_new}"'> /" -e "s/^\< /'"${DIFF_file_old}"'< /" -e "s/^[0-9]+/'"${DIFF_diffstuff}"'&/"' set diffu_exprs = '-e "s/^\+/'"${DIFF_file_new}"'+/" -e "s/^-/'"${DIFF_file_old}"'-/" -e "s/^@@ /'"${DIFF_diffstuff}"'@@/" -e "s/^ /'"${DIFF_plain_text}"' /"' set diffc_exprs = '-e "s/^\*\*\* /'"${DIFF_file_new}"'*** /" -e "s/^--- /'"${DIFF_file_old}"'--- /" -e "s/^+ /'"${DIFF_added}"'+ /" -e "s/^- /'"${DIFF_removed}"'- /" -e "s/^! /'"${DIFF_changed}"'! /" -e "s/^\*\*\*\*/'"${DIFF_diffstuff}"'****/" -e "s/^ /'"${DIFF_plain_text}"' /"' alias diff-n 'diff --normal \!* | sed '"${diffn_exprs}" alias diff-u 'diff -u \!* | sed '"${diffu_exprs}" alias diff-c 'diff -c \!* | sed '"${diffc_exprs}" ### unset our temporary variables unset ANSI_* unset DIFF_* unset E endif endif if (-f ~/.cshrc.local) source ~/.cshrc.local