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