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