emacs: Highlight full tables of contents in Info.
[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
f617db13
MW
115# --- Set up some simple aliases ---
116
117alias cx='chmod a+x'
118alias which="command -v"
119alias ssync="rsync -e ssh"
f141fe0f 120alias rootly=$__MDW_ROOTLY
f617db13 121alias r=rootly
4832db48 122alias re="rootly $EDITOR"
a1545658 123alias pstree="pstree -hl"
f617db13
MW
124alias cdtmp='cd ${TMPDIR-/tmp}'
125alias pushtmp='pushd ${TMPDIR-/tmp}'
4832db48 126alias e="$EDITOR"
ed2a32e1 127alias svn="svnwrap svn"
4543696d 128alias @="ssh"
f617db13 129
75ff64d8
MW
130[ -r /etc/bash_completion ] && . /etc/bash_completion
131[ -r $HOME/.bash_completion ] && . $HOME/.bash_completion
132
f617db13
MW
133# --- Make `xt' start an xterm, maybe logging into a remote host ---
134
135xt () {
136 case "$1" in
137 @*)
138 local remote=${1#@} title
139 shift
140 if [ $# -gt 0 ]; then
141 title="xterm [$remote] $1"
142 else
143 title="xterm [$remote]"
144 fi
145 (xterm -title "$title" -e ssh $remote "$@" &)
146 ;;
147 *)
148 (xterm "$@" &)
149 ;;
150 esac
151}
152
153# --- Turning on and off core dumps ---
154
155core () {
156 case "x$1" in
157 xon|xy|xyes)
158 ulimit -Sc `ulimit -Hc`
159 ;;
160 xoff|xn|xno)
161 ulimit -Sc 0
162 ;;
163 x)
164 local l=`ulimit -Sc`
165 case $l in
166 0) echo "Core dumps disabled" ;;
167 unlimited) echo "Core dumps enabled" ;;
168 *) echo "Core dump limit is $l blocks" ;;
169 esac
170 ;;
171 *)
172 echo >&2 "usage: core [yn]"
173 return 1
174 ;;
175 esac
176}
177
32f790cc
MW
178# --- Turning on and off path hacks ---
179
180path-add () {
181 local pathvar export dir val
182 case $# in
183 1) pathvar=PATH dir=$1 export="export PATH";;
184 2) pathvar=$1 dir=$2 export=:;;
185 *) echo >&2 "Usage: $0 [VAR] DIR";;
186 esac
187 eval "val=\$$pathvar"
188 case ":$val:" in
189 *:"$dir":*) ;;
190 *) val=$dir:$val ;;
191 esac
192 eval "$pathvar=\$val"
193 $export
194}
195
196path-remove () {
197 local pathvar export dir val
198 case $# in
199 1) pathvar=PATH dir=$1 export="export PATH";;
200 2) pathvar=$1 dir=$2 export=:;;
201 *) echo >&2 "Usage: $0 [VAR] DIR";;
202 esac
203 eval "val=\$$pathvar"
204 case ":$val:" in
205 :"$dir":) val= ;;
206 :"$dir":*) val=${val#$dir:} ;;
207 *:"$dir":) val=${val%:$dir} ;;
208 *:"$dir":*) val=${val/:$dir:/:} ;;
209 esac
210 eval "$pathvar=\$val"
211 $export
212}
213
214pathhack () {
215 if [ $# -eq 0 ]; then
216 local IFS=:
217 for e in $PATH; do
218 case "$e" in
219 "$HOME/bin/hacks/"*)
220 echo ${e#$HOME/bin/hacks/}
221 ;;
222 esac
223 done
224 return
225 fi
226 local force=nil
227 local path=$PATH
228 while [ $# -gt 0 ]; do
229 arg=$1
230 case "$arg" in
231 -f | --force)
232 force=t
233 shift
234 continue
235 ;;
236 --)
852cd5fb 237 shift
32f790cc
MW
238 break
239 ;;
240 [-+]*)
852cd5fb 241 ;;
32f790cc 242 *)
852cd5fb 243 break
32f790cc
MW
244 ;;
245 esac
246 hack=${arg#[+-]}
247 dir=$HOME/bin/hacks/$hack
248 [ -d "$dir" ] || {
249 echo "$0: path hack $hack not found"
250 return 1
251 }
252 case "$arg,$force,:$PATH:" in
253 -*,*,*:"$dir":*)
852cd5fb 254 path-remove path "$dir"
32f790cc
MW
255 ;;
256 +*,t,*:"$dir":*)
852cd5fb 257 path-remove path "$dir"
32f790cc
MW
258 path-add path "$dir"
259 ;;
260 +*,nil,*:"$dir":*)
852cd5fb 261 ;;
32f790cc 262 +*,*)
852cd5fb 263 path-add path "$dir"
32f790cc
MW
264 ;;
265 esac
266 shift
267 done
268 if [ $# -eq 0 ]; then
269 PATH=$path
270 export PATH
271 else
272 PATH=$path "$@"
273 fi
274}
275
f617db13
MW
276# --- Fix `man' under Slowaris ---
277
278case "$MACHTYPE" in
279 *solaris*)
280 man () {
281 declare -i i=0
282 declare arg
283 declare -a man
284
285 for arg; do
286 case "$arg" in [0-9]*) man[i+=1]="-s" ;; esac
287 man[i+=1]="$arg"
288 done
289 command man "${man[@]}"
290 }
291 ;;
292esac
293
294# --- For `root' use -- some simple molly-guards ---
295
296if (( UID == 0 )); then
297 alias rm='rm -i' cp='cp -i' mv='mv -i'
298 set -o noclobber
299fi
300
68aea1d9
MW
301[ -f "$HOME/.bashrc-local" ] && . "$HOME/.bashrc-local"
302
f617db13 303fi