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