mdw-build: Bring into the fold.
[profile] / 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
72shopt -s histappend
73shopt -s histreedit
74shopt -u histverify
75shopt -s hostcomplete
76shopt -s huponexit
77shopt -s interactive_comments
78shopt -s lithist
79shopt -u mailwarn
80shopt -u nocaseglob
81shopt -u nullglob
82shopt -s promptvars
83shopt -u shift_verbose
84shopt -s sourcepath
85
86# --- Set the CDPATH ---
852cd5fb 87#
f617db13
MW
88# CDPATH=~/src:/usr/src:/usr/lib:/usr/share
89# dots=..
90# i=6
91# while (( i > 0 )); do
92# CDPATH=$CDPATH:$dots
93# dots=$dots/..
94# (( i -= 1 ))
95# done
96# CDPATH=$CDPATH:/
97
98# --- Some colour `ls' support ---
99
100[ "${TMPDIR+yes}" ] || eval `tmpdir -b`
15b95c26 101if [ -x /usr/bin/dircolors -o -x /usr/local/bin/dircolors ]; then
f617db13
MW
102 eval `dircolors -b ~/.dircolors`
103else
104 unset LS_COLORS
105fi
106
107ls () {
108 if [ -t 1 ]; then
109 command ls $LS_OPTIONS ${LS_COLORS+--color=auto} "$@"
110 else
111 command ls "$@"
112 fi
113}
114
bf3f5761
MW
115# --- Some colour `grep' support ---
116
117export GREP_COLORS="mt=01;31:ms=01;31:mc=031;31:fn=36:ln=36:bn=36:se=34"
118
119grep () {
120 if [ -t 1 ]; then
121 command grep ${GREP_COLORS+--color=auto} "$@"
122 else
123 command grep "$@"
124 fi
125}
126
f617db13
MW
127# --- Set up some simple aliases ---
128
129alias cx='chmod a+x'
130alias which="command -v"
131alias ssync="rsync -e ssh"
f141fe0f 132alias rootly=$__MDW_ROOTLY
f617db13 133alias r=rootly
4832db48 134alias re="rootly $EDITOR"
a1545658 135alias pstree="pstree -hl"
f617db13
MW
136alias cdtmp='cd ${TMPDIR-/tmp}'
137alias pushtmp='pushd ${TMPDIR-/tmp}'
4832db48 138alias e="$EDITOR"
ed2a32e1 139alias svn="svnwrap svn"
4543696d 140alias @="ssh"
f617db13 141
75ff64d8
MW
142[ -r /etc/bash_completion ] && . /etc/bash_completion
143[ -r $HOME/.bash_completion ] && . $HOME/.bash_completion
144
f617db13
MW
145# --- Make `xt' start an xterm, maybe logging into a remote host ---
146
147xt () {
148 case "$1" in
149 @*)
150 local remote=${1#@} title
151 shift
152 if [ $# -gt 0 ]; then
153 title="xterm [$remote] $1"
154 else
155 title="xterm [$remote]"
156 fi
157 (xterm -title "$title" -e ssh $remote "$@" &)
158 ;;
159 *)
160 (xterm "$@" &)
161 ;;
162 esac
163}
164
165# --- Turning on and off core dumps ---
166
167core () {
168 case "x$1" in
169 xon|xy|xyes)
170 ulimit -Sc `ulimit -Hc`
171 ;;
172 xoff|xn|xno)
173 ulimit -Sc 0
174 ;;
175 x)
176 local l=`ulimit -Sc`
177 case $l in
178 0) echo "Core dumps disabled" ;;
179 unlimited) echo "Core dumps enabled" ;;
180 *) echo "Core dump limit is $l blocks" ;;
181 esac
182 ;;
183 *)
184 echo >&2 "usage: core [yn]"
185 return 1
186 ;;
187 esac
188}
189
32f790cc
MW
190# --- Turning on and off path hacks ---
191
192path-add () {
193 local pathvar export dir val
194 case $# in
195 1) pathvar=PATH dir=$1 export="export PATH";;
196 2) pathvar=$1 dir=$2 export=:;;
197 *) echo >&2 "Usage: $0 [VAR] DIR";;
198 esac
199 eval "val=\$$pathvar"
200 case ":$val:" in
201 *:"$dir":*) ;;
202 *) val=$dir:$val ;;
203 esac
204 eval "$pathvar=\$val"
205 $export
206}
207
208path-remove () {
209 local pathvar export dir val
210 case $# in
211 1) pathvar=PATH dir=$1 export="export PATH";;
212 2) pathvar=$1 dir=$2 export=:;;
213 *) echo >&2 "Usage: $0 [VAR] DIR";;
214 esac
215 eval "val=\$$pathvar"
216 case ":$val:" in
217 :"$dir":) val= ;;
218 :"$dir":*) val=${val#$dir:} ;;
219 *:"$dir":) val=${val%:$dir} ;;
220 *:"$dir":*) val=${val/:$dir:/:} ;;
221 esac
222 eval "$pathvar=\$val"
223 $export
224}
225
226pathhack () {
227 if [ $# -eq 0 ]; then
228 local IFS=:
229 for e in $PATH; do
230 case "$e" in
231 "$HOME/bin/hacks/"*)
232 echo ${e#$HOME/bin/hacks/}
233 ;;
234 esac
235 done
236 return
237 fi
238 local force=nil
239 local path=$PATH
240 while [ $# -gt 0 ]; do
241 arg=$1
242 case "$arg" in
243 -f | --force)
244 force=t
245 shift
246 continue
247 ;;
248 --)
852cd5fb 249 shift
32f790cc
MW
250 break
251 ;;
252 [-+]*)
852cd5fb 253 ;;
32f790cc 254 *)
852cd5fb 255 break
32f790cc
MW
256 ;;
257 esac
258 hack=${arg#[+-]}
259 dir=$HOME/bin/hacks/$hack
260 [ -d "$dir" ] || {
261 echo "$0: path hack $hack not found"
262 return 1
263 }
264 case "$arg,$force,:$PATH:" in
265 -*,*,*:"$dir":*)
852cd5fb 266 path-remove path "$dir"
32f790cc
MW
267 ;;
268 +*,t,*:"$dir":*)
852cd5fb 269 path-remove path "$dir"
32f790cc
MW
270 path-add path "$dir"
271 ;;
272 +*,nil,*:"$dir":*)
852cd5fb 273 ;;
32f790cc 274 +*,*)
852cd5fb 275 path-add path "$dir"
32f790cc
MW
276 ;;
277 esac
278 shift
279 done
280 if [ $# -eq 0 ]; then
281 PATH=$path
282 export PATH
283 else
284 PATH=$path "$@"
285 fi
286}
287
f617db13
MW
288# --- Fix `man' under Slowaris ---
289
290case "$MACHTYPE" in
291 *solaris*)
292 man () {
293 declare -i i=0
294 declare arg
295 declare -a man
296
297 for arg; do
298 case "$arg" in [0-9]*) man[i+=1]="-s" ;; esac
299 man[i+=1]="$arg"
300 done
301 command man "${man[@]}"
302 }
303 ;;
304esac
305
306# --- For `root' use -- some simple molly-guards ---
307
308if (( UID == 0 )); then
309 alias rm='rm -i' cp='cp -i' mv='mv -i'
310 set -o noclobber
311fi
312
68aea1d9
MW
313[ -f "$HOME/.bashrc-local" ] && . "$HOME/.bashrc-local"
314
f617db13 315fi