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 utf8 -t //translit`
39 right=`echo » | iconv -f utf8 -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"
101 alias rootly=$__MDW_ROOTLY
103 alias re="rootly $EDITOR"
104 alias pstree="pstree -hl"
105 alias cdtmp='cd ${TMPDIR-/tmp}'
106 alias pushtmp='pushd ${TMPDIR-/tmp}'
108 alias svn="svnwrap svn"
112 [ -r /etc/bash_completion ] && . /etc/bash_completion
113 [ -r $HOME/.bash_completion ] && . $HOME/.bash_completion
115 ###--------------------------------------------------------------------------
118 ## Arrange for `ls' output to be in colour.
119 if [ -x /usr/bin/dircolors -o -x /usr/local/bin/dircolors ]; then
120 eval `dircolors -b ~/.dircolors`
127 command ls $LS_OPTIONS ${LS_COLORS+--color=auto} "$@"
133 ## Arrange for `grep' output to be in colour.
134 export GREP_COLORS="mt=01;31:ms=01;31:mc=031;31:fn=36:ln=36:bn=36:se=34"
137 declare grep=$1; shift
139 command $grep ${GREP_COLORS+--color=always} "$@" | mdw-pager
144 alias grep="greplike grep"
145 alias egrep="greplike egrep"
146 alias fgrep="greplike fgrep"
147 alias zgrep="greplike zgrep"
149 ## Turn off pagers inside Emacs shell buffers.
150 case "$INSIDE_EMACS" in
151 22.*,comint) export PAGER=cat ;;
154 ###--------------------------------------------------------------------------
155 ### More complicated shell functions.
157 ## xt [@HOST] XTERM-ARGS
159 ## Open a terminal, maybe on a remote host.
163 local remote=${1#@} title
165 if [ $# -gt 0 ]; then
166 title="xterm [$remote] $1"
168 title="xterm [$remote]"
170 (xterm -title "$title" -e ssh $remote "$@" &)
180 ## Tweak core dumps on and off, or show the current status.
183 xon|xy|xyes) ulimit -Sc `ulimit -Hc` ;;
184 xoff|xn|xno) ulimit -Sc 0 ;;
188 0) echo "Core dumps disabled" ;;
189 unlimited) echo "Core dumps enabled" ;;
190 *) echo "Core dump limit is $l blocks" ;;
194 echo >&2 "usage: core [y|n]"
202 ## Set current security world to NAME. With no NAME, print the currently
205 local nfast=${NFAST_HOME-/opt/nfast}
209 echo "${NFAST_KMDATA#$nfast/kmdata-}"
214 elif [ -d "$nfast/kmdata-$1" ]; then
215 kmdata=$nfast/kmdata-$1
217 echo >&2 "world: can't find world $1"
222 0) export NFAST_KMDATA=$kmdata ;;
229 ## Fix `man' under Slowaris.
237 case "$arg" in [0-9]*) man[i+=1]="-s" ;; esac
240 command man "${man[@]}"
245 ###--------------------------------------------------------------------------
248 ## path-add [VAR] DIR
250 ## Add DIR to the beginning of PATH-like variable VAR (defaults to PATH) if
251 ## it's not there already.
253 local pathvar export dir val
255 1) pathvar=PATH dir=$1 export="export PATH";;
256 2) pathvar=$1 dir=$2 export=:;;
257 *) echo >&2 "Usage: $0 [VAR] DIR";;
259 eval "val=\$$pathvar"
264 eval "$pathvar=\$val"
268 ## path-remove [VAR] DIR
270 ## Remove DIR from PATH-like variable VAR (defaults to PATH); it's not an
271 ## error if DIR isn't in VAR.
273 local pathvar export dir val
275 1) pathvar=PATH dir=$1 export="export PATH";;
276 2) pathvar=$1 dir=$2 export=:;;
277 *) echo >&2 "Usage: $0 [VAR] DIR";;
279 eval "val=\$$pathvar"
282 :"$dir":*) val=${val#$dir:} ;;
283 *:"$dir":) val=${val%:$dir} ;;
284 *:"$dir":*) val=${val/:$dir:/:} ;;
286 eval "$pathvar=\$val"
290 ## pathhack [-f] +HACK|-HACK...
292 ## Each HACK refers to a subdirectory of `~/bin/hacks'. A hack name preceded
293 ## by `+' adds the directory to the PATH; a `-' removes. Adding a hack
294 ## that's already on the PATH doesn't do anything unless `-f' is set, in
295 ## which case it gets moved to the beginning. With no arguments, print the
296 ## currently installed hacks.
298 if [ $# -eq 0 ]; then
303 echo ${e#$HOME/bin/hacks/}
311 while [ $# -gt 0 ]; do
330 dir=$HOME/bin/hacks/$hack
332 echo "$0: path hack $hack not found"
335 case "$arg,$force,:$PATH:" in
337 path-remove path "$dir"
340 path-remove path "$dir"
351 if [ $# -eq 0 ]; then
359 ###--------------------------------------------------------------------------
360 ### Finishing touches.
362 ## For `root' use -- some simple molly-guards.
363 if (( UID == 0 )); then
364 alias rm='rm -i' cp='cp -i' mv='mv -i'
368 ## Run any local hooks.
369 [ -f "$HOME/.bashrc-local" ] && . "$HOME/.bashrc-local"
371 ## Close the `__mdw_bashrc' guard.
374 ###----- That's all, folks --------------------------------------------------