mc: Store configuration and arrange for linkage.
[profile] / dot / bashrc
CommitLineData
bc30f5c4 1# -*- mode: sh; coding: utf-8 -*-
f617db13 2#
f617db13
MW
3# Bash session things
4#
5
6if [ -z "$__mdw_bashrc" ]; then
7
8__mdw_bashrc=done
9
10[ -z "$__mdw_profile" -a -r $HOME/.bash_profile ] && . $HOME/.bash_profile
11[ -r /etc/bashrc ] && . /etc/bashrc
12
13# --- First of all, set up the prompt string ---
14
15if [ -t 0 ]; then
16
15b95c26
MW
17 case "$TERM" in
18 linux*|screen*|xterm*|vt100*|eterm*)
19 bold="\[$(tput bold)\]" unbold="\[$(tput sgr0)\]" nl="\[\r\]" ;;
20 *)
21 bold='' unbold='' nl='' ;;
22 esac
23
24 if (( EUID == 0 )); then
25 left=`echo « | iconv -f utf8 -t //translit`
26 right=`echo » | iconv -f utf8 -t //translit`
f617db13 27 else
15b95c26
MW
28 case $USER in
29 mdw|mwooding)
30 u="" left="[" right="]"
31 ;;
f617db13 32 *)
15b95c26
MW
33 u="\\u@" left="{" right="}"
34 ;;
f617db13 35 esac
15b95c26
MW
36 if [ "$__mdw_tty" = "`tty`" ]; then
37 left="<" right=">"
f617db13 38 else
15b95c26 39 export __mdw_tty="`tty`"
f617db13 40 fi
15b95c26 41 fi
f617db13 42
15b95c26
MW
43 if [ -z "$SSH_CLIENT" ] &&
44 [ "$__mdw_sechost" != "`hostname`" ]
45 then
46 sec_l='(' sec_r=')'
f617db13
MW
47 fi
48
15b95c26
MW
49 PS1="$nl$bold$left$sec_l$u\\h$sec_r \\w$right$unbold"
50 PS2="$PS1 $bold>$unbold "
51
f617db13
MW
52fi # is stdin a tty?
53
15b95c26
MW
54# --- Pagers are less useful within Emacs ---
55
56case "$INSIDE_EMACS" in
57 22.*,comint) export PAGER=cat ;;
58esac
59
f617db13
MW
60# --- Little preferences ---
61
62notify=1
63set -b
64shopt -u cdable_vars
65shopt -s cdspell
66shopt -s checkhash
67shopt -s checkwinsize
68shopt -s cmdhist
69shopt -u dotglob
70shopt -s expand_aliases
71shopt -s extglob
83a3b1eb
MW
72shopt -s globstar
73shopt -s gnu_errfmt
f617db13
MW
74shopt -s histappend
75shopt -s histreedit
76shopt -u histverify
77shopt -s hostcomplete
78shopt -s huponexit
79shopt -s interactive_comments
80shopt -s lithist
81shopt -u mailwarn
82shopt -u nocaseglob
83shopt -u nullglob
84shopt -s promptvars
85shopt -u shift_verbose
86shopt -s sourcepath
87
83a3b1eb
MW
88HISTCONTROL=ignorespace:erasedups
89
f617db13 90# --- Set the CDPATH ---
852cd5fb 91#
f617db13
MW
92# CDPATH=~/src:/usr/src:/usr/lib:/usr/share
93# dots=..
94# i=6
95# while (( i > 0 )); do
96# CDPATH=$CDPATH:$dots
97# dots=$dots/..
98# (( i -= 1 ))
99# done
100# CDPATH=$CDPATH:/
101
102# --- Some colour `ls' support ---
103
104[ "${TMPDIR+yes}" ] || eval `tmpdir -b`
15b95c26 105if [ -x /usr/bin/dircolors -o -x /usr/local/bin/dircolors ]; then
f617db13
MW
106 eval `dircolors -b ~/.dircolors`
107else
108 unset LS_COLORS
109fi
110
111ls () {
112 if [ -t 1 ]; then
113 command ls $LS_OPTIONS ${LS_COLORS+--color=auto} "$@"
114 else
115 command ls "$@"
116 fi
117}
118
bf3f5761
MW
119# --- Some colour `grep' support ---
120
121export GREP_COLORS="mt=01;31:ms=01;31:mc=031;31:fn=36:ln=36:bn=36:se=34"
122
004beb57
MW
123greplike () {
124 declare grep=$1; shift
bf3f5761 125 if [ -t 1 ]; then
a085e9a8 126 command $grep ${GREP_COLORS+--color=always} "$@" | mdw-pager
bf3f5761 127 else
004beb57 128 command $grep "$@"
bf3f5761
MW
129 fi
130}
004beb57
MW
131alias grep="greplike grep"
132alias egrep="greplike egrep"
133alias fgrep="greplike fgrep"
4da2e817 134alias zgrep="greplike zgrep"
bf3f5761 135
f617db13
MW
136# --- Set up some simple aliases ---
137
138alias cx='chmod a+x'
139alias which="command -v"
2c49e081 140alias rc="rc -l"
f617db13 141alias ssync="rsync -e ssh"
f141fe0f 142alias rootly=$__MDW_ROOTLY
f617db13 143alias r=rootly
4832db48 144alias re="rootly $EDITOR"
a1545658 145alias pstree="pstree -hl"
f617db13
MW
146alias cdtmp='cd ${TMPDIR-/tmp}'
147alias pushtmp='pushd ${TMPDIR-/tmp}'
4832db48 148alias e="$EDITOR"
ed2a32e1 149alias svn="svnwrap svn"
4543696d 150alias @="ssh"
f617db13 151
75ff64d8
MW
152[ -r /etc/bash_completion ] && . /etc/bash_completion
153[ -r $HOME/.bash_completion ] && . $HOME/.bash_completion
154
f617db13
MW
155# --- Make `xt' start an xterm, maybe logging into a remote host ---
156
157xt () {
158 case "$1" in
159 @*)
160 local remote=${1#@} title
161 shift
162 if [ $# -gt 0 ]; then
163 title="xterm [$remote] $1"
164 else
165 title="xterm [$remote]"
166 fi
167 (xterm -title "$title" -e ssh $remote "$@" &)
168 ;;
169 *)
170 (xterm "$@" &)
171 ;;
172 esac
173}
174
175# --- Turning on and off core dumps ---
176
177core () {
178 case "x$1" in
179 xon|xy|xyes)
180 ulimit -Sc `ulimit -Hc`
181 ;;
182 xoff|xn|xno)
183 ulimit -Sc 0
184 ;;
185 x)
186 local l=`ulimit -Sc`
187 case $l in
188 0) echo "Core dumps disabled" ;;
189 unlimited) echo "Core dumps enabled" ;;
190 *) echo "Core dump limit is $l blocks" ;;
191 esac
192 ;;
193 *)
194 echo >&2 "usage: core [yn]"
195 return 1
196 ;;
197 esac
198}
199
32f790cc
MW
200# --- Turning on and off path hacks ---
201
202path-add () {
203 local pathvar export dir val
204 case $# in
205 1) pathvar=PATH dir=$1 export="export PATH";;
206 2) pathvar=$1 dir=$2 export=:;;
207 *) echo >&2 "Usage: $0 [VAR] DIR";;
208 esac
209 eval "val=\$$pathvar"
210 case ":$val:" in
211 *:"$dir":*) ;;
212 *) val=$dir:$val ;;
213 esac
214 eval "$pathvar=\$val"
215 $export
216}
217
218path-remove () {
219 local pathvar export dir val
220 case $# in
221 1) pathvar=PATH dir=$1 export="export PATH";;
222 2) pathvar=$1 dir=$2 export=:;;
223 *) echo >&2 "Usage: $0 [VAR] DIR";;
224 esac
225 eval "val=\$$pathvar"
226 case ":$val:" in
227 :"$dir":) val= ;;
228 :"$dir":*) val=${val#$dir:} ;;
229 *:"$dir":) val=${val%:$dir} ;;
230 *:"$dir":*) val=${val/:$dir:/:} ;;
231 esac
232 eval "$pathvar=\$val"
233 $export
234}
235
236pathhack () {
237 if [ $# -eq 0 ]; then
238 local IFS=:
239 for e in $PATH; do
240 case "$e" in
241 "$HOME/bin/hacks/"*)
242 echo ${e#$HOME/bin/hacks/}
243 ;;
244 esac
245 done
246 return
247 fi
248 local force=nil
249 local path=$PATH
250 while [ $# -gt 0 ]; do
251 arg=$1
252 case "$arg" in
253 -f | --force)
254 force=t
255 shift
256 continue
257 ;;
258 --)
852cd5fb 259 shift
32f790cc
MW
260 break
261 ;;
262 [-+]*)
852cd5fb 263 ;;
32f790cc 264 *)
852cd5fb 265 break
32f790cc
MW
266 ;;
267 esac
268 hack=${arg#[+-]}
269 dir=$HOME/bin/hacks/$hack
270 [ -d "$dir" ] || {
271 echo "$0: path hack $hack not found"
272 return 1
273 }
274 case "$arg,$force,:$PATH:" in
275 -*,*,*:"$dir":*)
852cd5fb 276 path-remove path "$dir"
32f790cc
MW
277 ;;
278 +*,t,*:"$dir":*)
852cd5fb 279 path-remove path "$dir"
32f790cc
MW
280 path-add path "$dir"
281 ;;
282 +*,nil,*:"$dir":*)
852cd5fb 283 ;;
32f790cc 284 +*,*)
852cd5fb 285 path-add path "$dir"
32f790cc
MW
286 ;;
287 esac
288 shift
289 done
290 if [ $# -eq 0 ]; then
291 PATH=$path
292 export PATH
293 else
294 PATH=$path "$@"
295 fi
296}
297
c08211aa
MW
298# --- Switching security worlds ---
299
300world () {
301 local nfast=${NFAST_HOME-/opt/nfast}
302 local kmdata
303 case "$#" in
304 0)
305 echo "${NFAST_KMDATA#$nfast/kmdata-}"
306 ;;
307 *)
308 if [ -d "$1" ]; then
309 kmdata=$1
310 elif [ -d "$nfast/kmdata-$1" ]; then
311 kmdata=$nfast/kmdata-$1
312 else
313 echo >&2 "world: can't find world $1"
314 return 1
315 fi
316 shift
317 case "$#" in
318 0) export NFAST_KMDATA=$kmdata ;;
319 *) "$@" ;;
320 esac
321 ;;
322 esac
323}
324
f617db13
MW
325# --- Fix `man' under Slowaris ---
326
327case "$MACHTYPE" in
328 *solaris*)
329 man () {
330 declare -i i=0
331 declare arg
332 declare -a man
333
334 for arg; do
335 case "$arg" in [0-9]*) man[i+=1]="-s" ;; esac
336 man[i+=1]="$arg"
337 done
338 command man "${man[@]}"
339 }
340 ;;
341esac
342
343# --- For `root' use -- some simple molly-guards ---
344
345if (( UID == 0 )); then
346 alias rm='rm -i' cp='cp -i' mv='mv -i'
347 set -o noclobber
348fi
349
68aea1d9
MW
350[ -f "$HOME/.bashrc-local" ] && . "$HOME/.bashrc-local"
351
f617db13 352fi