chiark / gitweb /
pathhack [-f] [+HACK|-HACK] [--] [COMMAND [ARGS...]]
[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 # --- 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 fi