chiark / gitweb /
lisp-init.lisp: Make the CLisp namestring parsing less mad.
[profile] / bashrc
1 # -*- mode: sh; coding: utf-8 -*-
2 #
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   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`
27   else
28     case $USER in
29       mdw|mwooding)
30         u="" left="[" right="]"
31         ;;
32       *)
33         u="\\u@" left="{" right="}"
34         ;;
35     esac
36     if [ "$__mdw_tty" = "`tty`" ]; then
37       left="<" right=">"
38     else
39       export __mdw_tty="`tty`"
40     fi
41   fi
42
43   if [ -z "$SSH_CLIENT" ] &&
44     [ "$__mdw_sechost" != "`hostname`" ]
45     then
46     sec_l='(' sec_r=')'
47   fi
48
49   PS1="$nl$bold$left$sec_l$u\\h$sec_r \\w$right$unbold"
50   PS2="$PS1 $bold>$unbold "
51
52 fi # is stdin a tty?
53
54 # --- Pagers are less useful within Emacs ---
55
56 case "$INSIDE_EMACS" in
57   22.*,comint) export PAGER=cat ;;
58 esac
59
60 # --- Little preferences ---
61
62 notify=1
63 set -b
64 shopt -u cdable_vars
65 shopt -s cdspell
66 shopt -s checkhash
67 shopt -s checkwinsize
68 shopt -s cmdhist
69 shopt -u dotglob
70 shopt -s expand_aliases
71 shopt -s extglob
72 shopt -s histappend
73 shopt -s histreedit
74 shopt -u histverify
75 shopt -s hostcomplete
76 shopt -s huponexit
77 shopt -s interactive_comments
78 shopt -s lithist
79 shopt -u mailwarn
80 shopt -u nocaseglob
81 shopt -u nullglob
82 shopt -s promptvars
83 shopt -u shift_verbose
84 shopt -s sourcepath
85
86 # --- Set the CDPATH ---
87 #
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`
101 if [ -x /usr/bin/dircolors -o -x /usr/local/bin/dircolors ]; then
102   eval `dircolors -b ~/.dircolors`
103 else
104   unset LS_COLORS
105 fi
106
107 ls () {
108   if [ -t 1 ]; then
109     command ls $LS_OPTIONS ${LS_COLORS+--color=auto} "$@"
110   else
111     command ls "$@"
112   fi
113 }
114
115 # --- Set up some simple aliases ---
116
117 alias cx='chmod a+x'
118 alias which="command -v"
119 alias ssync="rsync -e ssh"
120 alias rootly=$__MDW_ROOTLY
121 alias r=rootly
122 alias re="rootly $EDITOR"
123 alias pstree="pstree -hl"
124 alias cdtmp='cd ${TMPDIR-/tmp}'
125 alias pushtmp='pushd ${TMPDIR-/tmp}'
126 alias e="$EDITOR"
127 alias svn="svnwrap svn"
128 alias @="ssh"
129
130 [ -r /etc/bash_completion ] && . /etc/bash_completion
131 [ -r $HOME/.bash_completion ] && . $HOME/.bash_completion
132
133 # --- Make `xt' start an xterm, maybe logging into a remote host ---
134
135 xt () {
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
155 core () {
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
178 # --- Turning on and off path hacks ---
179
180 path-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
196 path-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
214 pathhack () {
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       --)
237         shift
238         break
239         ;;
240       [-+]*)
241         ;;
242       *)
243         break
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":*)
254         path-remove path "$dir"
255         ;;
256       +*,t,*:"$dir":*)
257         path-remove path "$dir"
258         path-add path "$dir"
259         ;;
260       +*,nil,*:"$dir":*)
261         ;;
262       +*,*)
263         path-add path "$dir"
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
276 # --- Fix `man' under Slowaris ---
277
278 case "$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     ;;
292 esac
293
294 # --- For `root' use -- some simple molly-guards ---
295
296 if (( UID == 0 )); then
297   alias rm='rm -i' cp='cp -i' mv='mv -i'
298   set -o noclobber
299 fi
300
301 [ -f "$HOME/.bashrc-local" ] && . "$HOME/.bashrc-local"
302
303 fi