chiark / gitweb /
Initial import of my profile.
[profile] / bashrc
1 #
2 # $Id: .bashrc,v 1.6 1996/12/08 20:33:42 mdw Exp $
3 #
4 # Bash session things
5 #
6
7 if [ -z "$__mdw_bashrc" ]; then
8
9 __mdw_bashrc=done
10
11 [ -z "$__mdw_profile" -a -r $HOME/.bash_profile ] && . $HOME/.bash_profile
12 [ -r /etc/bashrc ] && . /etc/bashrc
13
14 # --- First of all, set up the prompt string ---
15
16 if [ -t 0 ]; then
17
18   if [ "$TERM" = "dumb" ]; then
19     if (( EUID == 0 )); then PS1="# "; else PS1="\$ "; fi
20     PS2="> "
21     PS4="+ "
22   else
23     
24     case "$TERM" in
25       linux*|screen*|xterm*|vt100*)
26         bold='\[\e[1m\]' unbold='\[\e[m\]' nl='\[\r\]' ;;
27       *)
28         bold='' unbold='' nl='' ;;
29     esac
30
31     if (( EUID == 0 )); then
32       left="«" right="»"
33     elif [ "$__mdw_tty" = "`tty`" ]; then
34       left="<" right=">"
35     else
36       left="[" right="]"
37       export __mdw_tty="`tty`"
38     fi
39
40     if [ -z "$SSH_CLIENT" ] &&
41       [ "$__mdw_sechost" != "`hostname`" ]
42       then
43       sec_l='(' sec_r=')'
44     fi
45
46     PS1="$nl$bold$left$sec_l\\h$sec_r \\w$right$unbold"
47     PS2="$PS1 $bold>$unbold "
48   fi
49
50 fi # is stdin a tty?
51
52 # --- Little preferences ---
53
54 notify=1
55 set -b
56 shopt -u cdable_vars
57 shopt -s cdspell
58 shopt -s checkhash
59 shopt -s checkwinsize
60 shopt -s cmdhist
61 shopt -u dotglob
62 shopt -s expand_aliases
63 shopt -s extglob
64 shopt -s histappend
65 shopt -s histreedit
66 shopt -u histverify
67 shopt -s hostcomplete
68 shopt -s huponexit
69 shopt -s interactive_comments
70 shopt -s lithist
71 shopt -u mailwarn
72 shopt -u nocaseglob
73 shopt -u nullglob
74 shopt -s promptvars
75 shopt -u shift_verbose
76 shopt -s sourcepath
77
78 # --- Set the CDPATH ---
79
80 # CDPATH=~/src:/usr/src:/usr/lib:/usr/share
81 # dots=..
82 # i=6
83 # while (( i > 0 )); do
84 #   CDPATH=$CDPATH:$dots
85 #   dots=$dots/..
86 #   (( i -= 1 ))
87 # done
88 # CDPATH=$CDPATH:/
89
90 # --- Some colour `ls' support ---
91
92 [ "${TMPDIR+yes}" ] || eval `tmpdir -b`
93 if [ -x /usr/bin/dircolors -o -x /usr/local/bin/dircolors ] &&
94    [ "$TERM" != "dumb" ]; then
95   eval `dircolors -b ~/.dircolors`
96 else
97   unset LS_COLORS
98 fi
99
100 ls () {
101   if [ -t 1 ]; then
102     command ls $LS_OPTIONS ${LS_COLORS+--color=auto} "$@"
103   else
104     command ls "$@"
105   fi
106 }
107
108 # --- Setting xterm titles ---
109 #
110 # This doesn't work so well any more. :-(
111
112 # if [ -e /usr/lib/bash/xtitle.so ]; then
113 #   enable -f /usr/lib/bash/xtitle.so xtitle
114 # elif [ -e /usr/local/lib/xtitle.so ]; then
115 #   enable -f /usr/local/lib/xtitle.so xtitle
116 # elif [ -e $HOME/lib/bash/xtitle.so ]; then
117 #   enable -f $HOME/lib/bash/xtitle.so xtitle
118 # else
119 #   xtitle () { return 1; }
120 # fi
121 xtitle () { return 1; }
122
123 entitle () {
124   local t="`xtitle -q`" st
125   xtitle "$t $1"
126   shift
127   "$@"; st=$?
128   xtitle "$t"
129   return $st
130 }
131
132 # --- Set up some simple aliases ---
133
134 alias cx='chmod a+x'
135 alias which="command -v"
136 alias ssync="rsync -e ssh"
137 alias rootly="entitle root become -g0 root"
138 alias r=rootly
139 alias eh="entitle 'Egham Hills 90210' tf eh"
140 alias news="entitle Usenet slrn"
141 alias splitvt='splitvt -t "`xtitle -q || echo xterm` splitvt"'
142 alias pstree="pstree -Ghl"
143 alias cdtmp='cd ${TMPDIR-/tmp}'
144 alias pushtmp='pushd ${TMPDIR-/tmp}'
145 alias e="sensible-editor"
146 alias svn=svnwrap
147
148 @ () {
149   local t="`xtitle -q`" host="$1"
150   shift
151   xtitle "$t [$host]"
152   ssh "$host" "$@"
153   xtitle "$t"
154 }
155
156 # --- Make `xt' start an xterm, maybe logging into a remote host ---
157
158 xt () {
159   case "$1" in
160     @*)
161       local remote=${1#@} title
162       shift
163       if [ $# -gt 0 ]; then
164         title="xterm [$remote] $1"
165       else
166         title="xterm [$remote]"
167       fi
168       (xterm -title "$title" -e ssh $remote "$@" &)
169       ;;
170     *)
171       (xterm "$@" &)
172       ;;
173   esac
174 }
175
176 # --- Turning on and off core dumps ---
177
178 core () {
179   case "x$1" in
180     xon|xy|xyes)
181       ulimit -Sc `ulimit -Hc`
182       ;;
183     xoff|xn|xno)
184       ulimit -Sc 0
185       ;;
186     x)
187       local l=`ulimit -Sc`
188       case $l in
189         0) echo "Core dumps disabled" ;;
190         unlimited) echo "Core dumps enabled" ;;
191         *) echo "Core dump limit is $l blocks" ;;
192       esac
193       ;;
194     *)
195       echo >&2 "usage: core [yn]"
196       return 1
197       ;;
198   esac
199 }
200
201 # --- Fix `man' under Slowaris ---
202
203 case "$MACHTYPE" in
204   *solaris*)
205     man () {
206       declare -i i=0
207       declare arg
208       declare -a man
209
210       for arg; do
211         case "$arg" in [0-9]*) man[i+=1]="-s" ;; esac
212         man[i+=1]="$arg"
213       done
214       command man "${man[@]}"
215     }
216     ;;
217 esac
218
219 # --- For `root' use -- some simple molly-guards ---
220
221 if (( UID == 0 )); then
222   alias rm='rm -i' cp='cp -i' mv='mv -i'
223   set -o noclobber
224 fi
225
226 fi