putty-defaults: Revert bogus change to Putty terminal height.
[profile] / bashrc
CommitLineData
bc30f5c4 1# -*- mode: sh; coding: utf-8 -*-
f617db13
MW
2#
3# $Id: .bashrc,v 1.6 1996/12/08 20:33:42 mdw Exp $
4#
5# Bash session things
6#
7
8if [ -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
17if [ -t 0 ]; then
18
19 if [ "$TERM" = "dumb" ]; then
20 if (( EUID == 0 )); then PS1="# "; else PS1="\$ "; fi
21 PS2="> "
22 PS4="+ "
23 else
852cd5fb 24
f617db13
MW
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
bc30f5c4
MW
33 left=`echo « | iconv -f utf8 -t //translit`
34 right=`echo » | iconv -f utf8 -t //translit`
f617db13 35 else
9a3fa88e 36 case $USER in
852cd5fb 37 mdw|mwooding)
9a3fa88e
MW
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
852cd5fb 47 export __mdw_tty="`tty`"
9a3fa88e 48 fi
f617db13
MW
49 fi
50
51 if [ -z "$SSH_CLIENT" ] &&
52 [ "$__mdw_sechost" != "`hostname`" ]
53 then
54 sec_l='(' sec_r=')'
55 fi
56
9a3fa88e 57 PS1="$nl$bold$left$sec_l$u\\h$sec_r \\w$right$unbold"
f617db13
MW
58 PS2="$PS1 $bold>$unbold "
59 fi
60
61fi # is stdin a tty?
62
63# --- Little preferences ---
64
65notify=1
66set -b
67shopt -u cdable_vars
68shopt -s cdspell
69shopt -s checkhash
70shopt -s checkwinsize
71shopt -s cmdhist
72shopt -u dotglob
73shopt -s expand_aliases
74shopt -s extglob
75shopt -s histappend
76shopt -s histreedit
77shopt -u histverify
78shopt -s hostcomplete
79shopt -s huponexit
80shopt -s interactive_comments
81shopt -s lithist
82shopt -u mailwarn
83shopt -u nocaseglob
84shopt -u nullglob
85shopt -s promptvars
86shopt -u shift_verbose
87shopt -s sourcepath
88
89# --- Set the CDPATH ---
852cd5fb 90#
f617db13
MW
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`
104if [ -x /usr/bin/dircolors -o -x /usr/local/bin/dircolors ] &&
105 [ "$TERM" != "dumb" ]; then
106 eval `dircolors -b ~/.dircolors`
107else
108 unset LS_COLORS
109fi
110
111ls () {
112 if [ -t 1 ]; then
113 command ls $LS_OPTIONS ${LS_COLORS+--color=auto} "$@"
114 else
115 command ls "$@"
116 fi
117}
118
f617db13
MW
119# --- Set up some simple aliases ---
120
121alias cx='chmod a+x'
122alias which="command -v"
123alias ssync="rsync -e ssh"
f141fe0f 124alias rootly=$__MDW_ROOTLY
f617db13 125alias r=rootly
4832db48 126alias re="rootly $EDITOR"
f617db13
MW
127alias pstree="pstree -Ghl"
128alias cdtmp='cd ${TMPDIR-/tmp}'
129alias pushtmp='pushd ${TMPDIR-/tmp}'
4832db48 130alias e="$EDITOR"
ed2a32e1 131alias svn="svnwrap svn"
4543696d 132alias @="ssh"
f617db13 133
75ff64d8
MW
134[ -r /etc/bash_completion ] && . /etc/bash_completion
135[ -r $HOME/.bash_completion ] && . $HOME/.bash_completion
136
f617db13
MW
137# --- Make `xt' start an xterm, maybe logging into a remote host ---
138
139xt () {
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
159core () {
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
32f790cc
MW
182# --- Turning on and off path hacks ---
183
184path-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
200path-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
218pathhack () {
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 --)
852cd5fb 241 shift
32f790cc
MW
242 break
243 ;;
244 [-+]*)
852cd5fb 245 ;;
32f790cc 246 *)
852cd5fb 247 break
32f790cc
MW
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":*)
852cd5fb 258 path-remove path "$dir"
32f790cc
MW
259 ;;
260 +*,t,*:"$dir":*)
852cd5fb 261 path-remove path "$dir"
32f790cc
MW
262 path-add path "$dir"
263 ;;
264 +*,nil,*:"$dir":*)
852cd5fb 265 ;;
32f790cc 266 +*,*)
852cd5fb 267 path-add path "$dir"
32f790cc
MW
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
f617db13
MW
280# --- Fix `man' under Slowaris ---
281
282case "$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 ;;
296esac
297
298# --- For `root' use -- some simple molly-guards ---
299
300if (( UID == 0 )); then
301 alias rm='rm -i' cp='cp -i' mv='mv -i'
302 set -o noclobber
303fi
304
68aea1d9
MW
305[ -f "$HOME/.bashrc-local" ] && . "$HOME/.bashrc-local"
306
f617db13 307fi