e16-bindings: Shortcuts to switch between desktops.
[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="\[ \]" ;;
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 # --- Some colour `grep' support ---
116
117 export GREP_COLORS="mt=01;31:ms=01;31:mc=031;31:fn=36:ln=36:bn=36:se=34"
118
119 grep () {
120 if [ -t 1 ]; then
121 command grep ${GREP_COLORS+--color=auto} "$@"
122 else
123 command grep "$@"
124 fi
125 }
126
127 # --- Set up some simple aliases ---
128
129 alias cx='chmod a+x'
130 alias which="command -v"
131 alias ssync="rsync -e ssh"
132 alias rootly=$__MDW_ROOTLY
133 alias r=rootly
134 alias re="rootly $EDITOR"
135 alias pstree="pstree -hl"
136 alias cdtmp='cd ${TMPDIR-/tmp}'
137 alias pushtmp='pushd ${TMPDIR-/tmp}'
138 alias e="$EDITOR"
139 alias svn="svnwrap svn"
140 alias @="ssh"
141
142 [ -r /etc/bash_completion ] && . /etc/bash_completion
143 [ -r $HOME/.bash_completion ] && . $HOME/.bash_completion
144
145 # --- Make `xt' start an xterm, maybe logging into a remote host ---
146
147 xt () {
148 case "$1" in
149 @*)
150 local remote=${1#@} title
151 shift
152 if [ $# -gt 0 ]; then
153 title="xterm [$remote] $1"
154 else
155 title="xterm [$remote]"
156 fi
157 (xterm -title "$title" -e ssh $remote "$@" &)
158 ;;
159 *)
160 (xterm "$@" &)
161 ;;
162 esac
163 }
164
165 # --- Turning on and off core dumps ---
166
167 core () {
168 case "x$1" in
169 xon|xy|xyes)
170 ulimit -Sc `ulimit -Hc`
171 ;;
172 xoff|xn|xno)
173 ulimit -Sc 0
174 ;;
175 x)
176 local l=`ulimit -Sc`
177 case $l in
178 0) echo "Core dumps disabled" ;;
179 unlimited) echo "Core dumps enabled" ;;
180 *) echo "Core dump limit is $l blocks" ;;
181 esac
182 ;;
183 *)
184 echo >&2 "usage: core [yn]"
185 return 1
186 ;;
187 esac
188 }
189
190 # --- Turning on and off path hacks ---
191
192 path-add () {
193 local pathvar export dir val
194 case $# in
195 1) pathvar=PATH dir=$1 export="export PATH";;
196 2) pathvar=$1 dir=$2 export=:;;
197 *) echo >&2 "Usage: $0 [VAR] DIR";;
198 esac
199 eval "val=\$$pathvar"
200 case ":$val:" in
201 *:"$dir":*) ;;
202 *) val=$dir:$val ;;
203 esac
204 eval "$pathvar=\$val"
205 $export
206 }
207
208 path-remove () {
209 local pathvar export dir val
210 case $# in
211 1) pathvar=PATH dir=$1 export="export PATH";;
212 2) pathvar=$1 dir=$2 export=:;;
213 *) echo >&2 "Usage: $0 [VAR] DIR";;
214 esac
215 eval "val=\$$pathvar"
216 case ":$val:" in
217 :"$dir":) val= ;;
218 :"$dir":*) val=${val#$dir:} ;;
219 *:"$dir":) val=${val%:$dir} ;;
220 *:"$dir":*) val=${val/:$dir:/:} ;;
221 esac
222 eval "$pathvar=\$val"
223 $export
224 }
225
226 pathhack () {
227 if [ $# -eq 0 ]; then
228 local IFS=:
229 for e in $PATH; do
230 case "$e" in
231 "$HOME/bin/hacks/"*)
232 echo ${e#$HOME/bin/hacks/}
233 ;;
234 esac
235 done
236 return
237 fi
238 local force=nil
239 local path=$PATH
240 while [ $# -gt 0 ]; do
241 arg=$1
242 case "$arg" in
243 -f | --force)
244 force=t
245 shift
246 continue
247 ;;
248 --)
249 shift
250 break
251 ;;
252 [-+]*)
253 ;;
254 *)
255 break
256 ;;
257 esac
258 hack=${arg#[+-]}
259 dir=$HOME/bin/hacks/$hack
260 [ -d "$dir" ] || {
261 echo "$0: path hack $hack not found"
262 return 1
263 }
264 case "$arg,$force,:$PATH:" in
265 -*,*,*:"$dir":*)
266 path-remove path "$dir"
267 ;;
268 +*,t,*:"$dir":*)
269 path-remove path "$dir"
270 path-add path "$dir"
271 ;;
272 +*,nil,*:"$dir":*)
273 ;;
274 +*,*)
275 path-add path "$dir"
276 ;;
277 esac
278 shift
279 done
280 if [ $# -eq 0 ]; then
281 PATH=$path
282 export PATH
283 else
284 PATH=$path "$@"
285 fi
286 }
287
288 # --- Fix `man' under Slowaris ---
289
290 case "$MACHTYPE" in
291 *solaris*)
292 man () {
293 declare -i i=0
294 declare arg
295 declare -a man
296
297 for arg; do
298 case "$arg" in [0-9]*) man[i+=1]="-s" ;; esac
299 man[i+=1]="$arg"
300 done
301 command man "${man[@]}"
302 }
303 ;;
304 esac
305
306 # --- For `root' use -- some simple molly-guards ---
307
308 if (( UID == 0 )); then
309 alias rm='rm -i' cp='cp -i' mv='mv -i'
310 set -o noclobber
311 fi
312
313 [ -f "$HOME/.bashrc-local" ] && . "$HOME/.bashrc-local"
314
315 fi