comparison .bashrc @ 66:91746c8abe0f

cleanup .bashrc
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 23 Apr 2010 15:40:46 -0700
parents a0636527f809
children a791d862148c
comparison
equal deleted inserted replaced
65:f47614ab462b 66:91746c8abe0f
27 alias svnst='svn st | grep -v "^\?"' 27 alias svnst='svn st | grep -v "^\?"'
28 alias awd="python -c 'import os; print os.path.realpath(\".\")'" 28 alias awd="python -c 'import os; print os.path.realpath(\".\")'"
29 alias distribute='python setup.py egg_info -RDb "" sdist register upload' 29 alias distribute='python setup.py egg_info -RDb "" sdist register upload'
30 alias random="python -c 'import sys, random; foo = sys.argv[1:]; random.shuffle(foo); print \" \".join(foo)'" 30 alias random="python -c 'import sys, random; foo = sys.argv[1:]; random.shuffle(foo); print \" \".join(foo)'"
31 31
32 # PROMPT
32 PS1='> ' 33 PS1='> '
33 PS2='. ' 34 PS2='. '
34 PROMPT_COMMAND='echo -ne "\033]0;${SSH_CLIENT/*/$HOSTNAME:}${PWD/~/~}\007"' 35 PROMPT_COMMAND='echo -ne "\033]0;${SSH_CLIENT/*/$HOSTNAME:}${PWD/~/~}\007"'
35 36
37 # PATHs
36 export PATH=~/bin:~/python:$PATH:/usr/sbin:/usr/games/bin 38 export PATH=~/bin:~/python:$PATH:/usr/sbin:/usr/games/bin
37 export PYTHONPATH=~/python:$PYTHONPATH 39 export PYTHONPATH=~/python:$PYTHONPATH
38 40
41
42 # functions
39 cdwin() { 43 cdwin() {
40 DIR=$(xwininfo | dictify.py xwininfo | awk '{ print $NF }' | sed 's/"//g') 44 DIR=$(xwininfo | dictify.py xwininfo | awk '{ print $NF }' | sed 's/"//g')
41 DIR=${DIR/\~/$HOME} 45 DIR=${DIR/\~/$HOME}
42 cd $DIR 46 cd $DIR
43 } 47 }
44 48
45 eend() { 49 eend() {
46 FILE=$1 50 FILE=$1
47 shift 51 shift
48 emacs +`wc -l "$FILE"` $@ 52 emacs +`wc -l "$FILE"` $@
49 }
50
51 # nice fast find function
52 EXCLUDES="(\.svn)|(\.mo$)|(\.po$)|(\.pyc$)"
53 ff() {
54
55 if (( $# < 2 ))
56 then
57 FILENAME='*' # default -- look in all files
58 else
59 FILENAME=$2
60 fi
61 CMD='command find -L $PWD -iname "${FILENAME}" -print0 | xargs -r0 grep -il "$1" | egrep -v "${EXCLUDES}"'
62 # echo $CMD
63 eval $CMD
64
65 }
66
67 chainff() {
68 if (( $# < 2 ))
69 then
70 return 0
71 fi
72
73 RESULTS=`ff "$2" "$1"`
74 shift 2
75
76 for i in $RESULTS
77 do
78 for arg in $@
79 do
80 if grep -il "$arg" "$i" &> /dev/null
81 then
82 touch /dev/null
83 else
84 i=""
85 break
86 fi
87 done
88 if [ -n "$i" ]
89 then
90 echo $i
91 fi
92 done
93 }
94
95 tmpfile() {
96
97
98 if [ "$#" == "0" ]
99 then
100 args="."
101 else
102 args=$@
103 fi
104
105 for i in $args
106 do
107 NEWNAME=${i}.$RANDOM
108
109 while [ -e $NEWNAME ]
110 do
111 NEWNAME=${NEWNAME}.tmp
112 done
113 echo "$NEWNAME"
114 done
115 }
116
117 edpe() {
118
119 # edit and pipe the buffer to stdout
120 FILE=`tmpfile`
121 $EDITOR $FILE
122 cat $FILE
123 rm $FILE
124
125 }
126
127 swap() {
128 if [ "$#" != "2" ]
129 then
130 echo "Usage: $FUNCNAME <first_arg> <second_arg>"
131 return
132 fi
133 for i in "$1" "$2"
134 do
135 if [ ! -w "$i" ]
136 then
137 echo "$FUNCNAME: Can't move $i"
138 return 1
139 fi
140 done
141
142 NEWNAME=`basename $1`.$RANDOM
143
144 while [ -e $NEWNAME ]
145 do
146 NEWNAME=${NEWNAME}.tmp
147 echo "$NEWNAME"
148 done
149
150 mv `basename $1` $NEWNAME
151 mv `basename $2` `basename $1`
152 mv $NEWNAME `basename $2`
153 }
154
155 isrunning() {
156 for i in "$@"
157 do
158 ps axwww | grep "$i" | grep -v 'grep'
159 done | sort | uniq
160
161 }
162
163 killbyname() {
164 kill `isrunning "$@" | awk '{ print $1 }' | onelineit.py`
165 }
166
167
168 tf() {
169 if [[ $@ ]]
170 then
171 echo "true"
172 else
173 echo "false"
174 fi
175 }
176
177 # full name
178 fn() {
179 python -c "import os; print os.path.realpath('$*')"
180 }
181
182 # which view
183 whview() {
184 less `which $@`
185 }
186
187 #which emacs
188 whemacs() {
189 emacs -nw `which $@`
190 }
191
192 pyfile() {
193 python -c "import $1; print $1.__file__"
194 } 53 }
195 54
196 function colors() { 55 function colors() {
197 56
198 CLR_WHITE="\033[0;37m" 57 CLR_WHITE="\033[0;37m"
211 CLR_PURPLEBOLD="\033[1;35m" 70 CLR_PURPLEBOLD="\033[1;35m"
212 CLR_YELLOW="\033[0;33m" 71 CLR_YELLOW="\033[0;33m"
213 CLR_YELLOWBOLD="\033[1;33m" 72 CLR_YELLOWBOLD="\033[1;33m"
214 CLR_NOTHING="\033[0m" 73 CLR_NOTHING="\033[0m"
215 } 74 }
216
217 colors 75 colors
76
77 # nice fast find function
78 EXCLUDES="(\.svn)|(\.mo$)|(\.po$)|(\.pyc$)"
79 ff() {
80
81 if (( $# < 2 ))
82 then
83 FILENAME='*' # default -- look in all files
84 else
85 FILENAME=$2
86 fi
87 CMD='command find -L $PWD -iname "${FILENAME}" -print0 | xargs -r0 grep -il "$1" | egrep -v "${EXCLUDES}"'
88 # echo $CMD
89 eval $CMD
90
91 }
92
93 chainff() {
94 if (( $# < 2 ))
95 then
96 return 0
97 fi
98
99 RESULTS=`ff "$2" "$1"`
100 shift 2
101
102 for i in $RESULTS
103 do
104 for arg in $@
105 do
106 if grep -il "$arg" "$i" &> /dev/null
107 then
108 touch /dev/null
109 else
110 i=""
111 break
112 fi
113 done
114 if [ -n "$i" ]
115 then
116 echo $i
117 fi
118 done
119 }
218 120
219 # contextual fastfind 121 # contextual fastfind
220 cff () { 122 cff () {
221 123
222 if (( $# < 2 )); then 124 if (( $# < 2 )); then
229 echo -e "$CLR_GREEN--->>> ""$CLR_YELLOWBOLD""$i""$CLR_NOTHING" : 131 echo -e "$CLR_GREEN--->>> ""$CLR_YELLOWBOLD""$i""$CLR_NOTHING" :
230 grep --color=auto -i -n -C 3 "$1" $i 132 grep --color=auto -i -n -C 3 "$1" $i
231 done 133 done
232 134
233 } 135 }
136
137 # make a temporary file
138 tmpfile() {
139
140 if [ "$#" == "0" ]
141 then
142 args="."
143 else
144 args=$@
145 fi
146
147 for i in $args
148 do
149 NEWNAME=${i}.$RANDOM
150
151 while [ -e $NEWNAME ]
152 do
153 NEWNAME=${NEWNAME}.tmp
154 done
155 echo "$NEWNAME"
156 done
157 }
158
159 edpe() {
160 # edit and pipe the buffer to stdout
161 FILE=`tmpfile`
162 $EDITOR $FILE
163 cat $FILE
164 rm $FILE
165 }
166
167 swap() {
168 if [ "$#" != "2" ]
169 then
170 echo "Usage: $FUNCNAME <first_arg> <second_arg>"
171 return
172 fi
173 for i in "$1" "$2"
174 do
175 if [ ! -w "$i" ]
176 then
177 echo "$FUNCNAME: Can't move $i"
178 return 1
179 fi
180 done
181
182 NEWNAME=`basename $1`.$RANDOM
183
184 while [ -e $NEWNAME ]
185 do
186 NEWNAME=${NEWNAME}.tmp
187 echo "$NEWNAME"
188 done
189
190 mv `basename $1` $NEWNAME
191 mv `basename $2` `basename $1`
192 mv $NEWNAME `basename $2`
193 }
194
195 isrunning() {
196 for i in "$@"
197 do
198 ps axwww | grep "$i" | grep -v 'grep'
199 done | sort | uniq
200
201 }
202
203 killbyname() {
204 kill `isrunning "$@" | awk '{ print $1 }' | onelineit.py`
205 }
206
207
208 tf() {
209 if [[ $@ ]]
210 then
211 echo "true"
212 else
213 echo "false"
214 fi
215 }
216
217 # full name
218 fn() {
219 python -c "import os; print os.path.realpath('$*')"
220 }
221
222 # which view
223 whview() {
224 less `which $@`
225 }
226
227 # which emacs
228 whemacs() {
229 emacs -nw `which $@`
230 }
231
232 pyfile() {
233 python -c "import $1; print $1.__file__"
234 }
234 235
235 svndance(){ 236 svndance(){
236 if (( $# )) 237 if (( $# ))
237 then 238 then
238 svn import $1 239 svn import $1