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