3 ### Bash session things
5 ## Only do this if we haven't done it before. (Note that this guard isn't
6 ## exported, so subshells will need to make their own arrangements.)
7 if [ -z "$__mdw_bashrc" ]; then
10 ## If we've not run the main profile yet, we should do that first. It sets
11 ## up things we rely on. Also, if there's a system script, we should run
13 [ -z "$__mdw_profile" -a -r $HOME/.bash_profile ] && . $HOME/.bash_profile
14 [ -r /etc/bashrc ] && . /etc/bashrc
16 ## Set the temporary directory again. (If we've switched users, we'll want a
17 ## different temporary directory.)
18 [ "${TMPDIR+yes}" ] || eval `tmpdir -b`
20 ###--------------------------------------------------------------------------
23 ## Only bother if the shell is interactive.
26 ## Fancy highlighting in some terminals.
28 linux*|screen*|xterm*|vt100*|eterm*)
29 bold="\[$(tput bold)\]" unbold="\[$(tput sgr0)\]" nl="\[
\r\]" ;;
31 bold='' unbold='' nl='' ;;
34 ## Choose the right delimiters. Highlight root prompts specially;
35 ## highlight when I'm running as some other user. Highlight when this
36 ## isn't the outermost shell on the terminal.
37 if (( EUID == 0 )); then
38 left=`echo « | iconv -f UTF-8 -t //translit`
39 right=`echo » | iconv -f UTF-8 -t //translit`
42 mdw|mwooding) u="" left="[" right="]" ;;
43 *) u="\\u@" left="{" right="}" ;;
45 if [ "$__mdw_tty" = "`tty`" ]; then
48 export __mdw_tty="`tty`"
52 ## If this session is insecure then highlight that.
53 if [ -z "$SSH_CLIENT" ] &&
54 [ "$__mdw_sechost" != "`hostname`" ]
59 ## Build the prompt string.
60 PS1="$nl$bold$left$sec_l$u\\h$sec_r \\w$right$unbold"
61 PS2="$PS1 $bold>$unbold "
65 ###--------------------------------------------------------------------------
66 ### Other shell tweaking.
68 ## Random shell tweaks.
77 shopt -s expand_aliases
86 shopt -s interactive_comments
92 shopt -u shift_verbose
94 HISTCONTROL=ignorespace:erasedups
96 ## Some handy aliases.
98 alias which="command -v"
100 alias ssync="rsync -e ssh"
102 case $# in 0) set -- "${SHELL-/bin/sh}" ;; esac
106 alias re="rootly $EDITOR"
107 alias pstree="pstree -hl"
108 alias cdtmp='cd ${TMPDIR-/tmp}'
109 alias pushtmp='pushd ${TMPDIR-/tmp}'
111 alias svn="svnwrap svn"
115 [ -r /etc/bash_completion ] && . /etc/bash_completion
116 [ -r $HOME/.bash_completion ] && . $HOME/.bash_completion
118 ###--------------------------------------------------------------------------
121 ## Arrange for `ls' output to be in colour.
122 if [ -x /usr/bin/dircolors -o -x /usr/local/bin/dircolors ]; then
123 eval `dircolors -b ~/.dircolors`
130 command ls $LS_OPTIONS ${LS_COLORS+--color=auto} "$@"
136 ## Arrange for `grep' output to be in colour.
137 export GREP_COLORS="mt=01;31:ms=01;31:mc=031;31:fn=36:ln=36:bn=36:se=34"
140 declare grep=$1; shift
142 command $grep ${GREP_COLORS+--color=always} "$@" | mdw-pager
147 alias grep="greplike grep"
148 alias egrep="greplike egrep"
149 alias fgrep="greplike fgrep"
150 alias zgrep="greplike zgrep"
152 ## Turn off pagers inside Emacs shell buffers.
153 case "$INSIDE_EMACS" in
154 22.*,comint) export PAGER=cat ;;
157 ###--------------------------------------------------------------------------
158 ### More complicated shell functions.
160 ## xt [@HOST] XTERM-ARGS
162 ## Open a terminal, maybe on a remote host.
166 local remote=${1#@} title
168 if [ $# -gt 0 ]; then
169 title="xterm [$remote] $1"
171 title="xterm [$remote]"
173 (xterm -title "$title" -e ssh $remote "$@" &)
183 ## Tweak core dumps on and off, or show the current status.
186 xon|xy|xyes) ulimit -Sc `ulimit -Hc` ;;
187 xoff|xn|xno) ulimit -Sc 0 ;;
191 0) echo "Core dumps disabled" ;;
192 unlimited) echo "Core dumps enabled" ;;
193 *) echo "Core dump limit is $l blocks" ;;
197 echo >&2 "usage: core [y|n]"
205 ## Set current security world to NAME. With no NAME, print the currently
208 local nfast=${NFAST_HOME-/opt/nfast}
212 echo "${NFAST_KMDATA#$nfast/kmdata-}"
217 elif [ -d "$nfast/kmdata-$1" ]; then
218 kmdata=$nfast/kmdata-$1
220 echo >&2 "world: can't find world $1"
225 0) export NFAST_KMDATA=$kmdata ;;
232 ## Fix `man' under Slowaris.
240 case "$arg" in [0-9]*) man[i+=1]="-s" ;; esac
243 command man "${man[@]}"
248 ###--------------------------------------------------------------------------
251 ## path-add [VAR] DIR
253 ## Add DIR to the beginning of PATH-like variable VAR (defaults to PATH) if
254 ## it's not there already.
256 local pathvar export dir val
258 1) pathvar=PATH dir=$1 export="export PATH";;
259 2) pathvar=$1 dir=$2 export=:;;
260 *) echo >&2 "Usage: $0 [VAR] DIR";;
262 eval "val=\$$pathvar"
267 eval "$pathvar=\$val"
271 ## path-remove [VAR] DIR
273 ## Remove DIR from PATH-like variable VAR (defaults to PATH); it's not an
274 ## error if DIR isn't in VAR.
276 local pathvar export dir val
278 1) pathvar=PATH dir=$1 export="export PATH";;
279 2) pathvar=$1 dir=$2 export=:;;
280 *) echo >&2 "Usage: $0 [VAR] DIR";;
282 eval "val=\$$pathvar"
285 :"$dir":*) val=${val#$dir:} ;;
286 *:"$dir":) val=${val%:$dir} ;;
287 *:"$dir":*) val=${val/:$dir:/:} ;;
289 eval "$pathvar=\$val"
293 ## pathhack [-f] +HACK|-HACK...
295 ## Each HACK refers to a subdirectory of `~/bin/hacks'. A hack name preceded
296 ## by `+' adds the directory to the PATH; a `-' removes. Adding a hack
297 ## that's already on the PATH doesn't do anything unless `-f' is set, in
298 ## which case it gets moved to the beginning. With no arguments, print the
299 ## currently installed hacks.
301 if [ $# -eq 0 ]; then
306 echo ${e#$HOME/bin/hacks/}
314 while [ $# -gt 0 ]; do
333 dir=$HOME/bin/hacks/$hack
335 echo "$0: path hack $hack not found"
338 case "$arg,$force,:$PATH:" in
340 path-remove path "$dir"
343 path-remove path "$dir"
354 if [ $# -eq 0 ]; then
362 ###--------------------------------------------------------------------------
363 ### Finishing touches.
365 ## For `root' use -- some simple molly-guards.
366 if (( UID == 0 )); then
367 alias rm='rm -i' cp='cp -i' mv='mv -i'
371 ## Run any local hooks.
372 [ -f "$HOME/.bashrc-local" ] && . "$HOME/.bashrc-local"
374 ## Close the `__mdw_bashrc' guard.
377 ###----- That's all, folks --------------------------------------------------