comparison .bashrc @ 539:1eaf74615f72

.bashrc
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 27 Sep 2013 11:50:02 -0700
parents 2881ea8897dc
children 8c9cd7472d28
comparison
equal deleted inserted replaced
538:2881ea8897dc 539:1eaf74615f72
159 CLR_NOTHING="\033[0m" 159 CLR_NOTHING="\033[0m"
160 } 160 }
161 colors 161 colors
162 162
163 163
164 eend() {
165 # edit the end of a file with emacs
166 FILE=$1
167 shift
168 emacs +`wc -l "$FILE"` $@
169 }
170
171 ### find functionality 164 ### find functionality
172 165
173 EXCLUDES="(\.svn)|(\.mo$)|(\.po$)|(\.pyc$)|(\.hg$)|(\.git$)" 166 EXCLUDES="(\.svn)|(\.mo$)|(\.po$)|(\.pyc$)|(\.hg$)|(\.git$)"
174 ff() { 167 ff() {
175 # nice fast find function 168 # nice fast find function
230 grep --color=auto -i -n -C 3 "$1" $i 223 grep --color=auto -i -n -C 3 "$1" $i
231 done 224 done
232 225
233 } 226 }
234 227
228 ### functions for files
229
235 tmpfile() { 230 tmpfile() {
236 # make a temporary file if `tempfile` not available 231 # make a temporary file if `tempfile` not available
237 232
238 if [ "$#" == "0" ] 233 if [ "$#" == "0" ]
239 then 234 then
251 NEWNAME=${NEWNAME}.tmp 246 NEWNAME=${NEWNAME}.tmp
252 done 247 done
253 echo "$NEWNAME" 248 echo "$NEWNAME"
254 done 249 done
255 } 250 }
251
252 fn() {
253 # full name
254 python -c "import os; print os.path.realpath('$*')"
255 }
256
257 swap() {
258 # swap two files
259 if [ "$#" != "2" ]
260 then
261 echo "Usage: $FUNCNAME <file1> <file2>"
262 return
263 fi
264 for i in "$1" "$2"
265 do
266 if [ ! -w "$i" ]
267 then
268 echo "$FUNCNAME: Can't move $i"
269 return 1
270 fi
271 done
272
273 NEWNAME=`basename $1`.$RANDOM
274 while [ -e $NEWNAME ]
275 do
276 NEWNAME=${NEWNAME}.tmp
277 echo "$NEWNAME"
278 done
279
280 mv "$1" "$NEWNAME"
281 mv "$2" "$1"
282 mv "$NEWNAME" "$2"
283 }
284
285
286 ### functions for editing
256 287
257 edpe() { 288 edpe() {
258 # edit and pipe the buffer to stdout 289 # edit and pipe the buffer to stdout
259 FILE=`tmpfile` 290 FILE=`tmpfile`
260 $EDITOR $FILE 291 $EDITOR $FILE
261 cat $FILE 292 cat $FILE
262 rm $FILE 293 rm $FILE
263 } 294 }
264 295
296 eend() {
297 # edit the end of a file with emacs
298 FILE=$1
299 shift
300 emacs +`wc -l "$FILE"` $@
301 }
302
303
304 ### functions for processes
305
265 isrunning() { 306 isrunning() {
266 # is a process running? (by name) 307 # is a process running? (by name)
267 # see also: talos for a better version 308 # see also: talos for a better version
268 for i in "$@" 309 for i in "$@"
269 do 310 do
275 killbyname() { 316 killbyname() {
276 # kill a process by name 317 # kill a process by name
277 kill `isrunning "$@" | awk '{ print $1 }' | onelineit.py` 318 kill `isrunning "$@" | awk '{ print $1 }' | onelineit.py`
278 } 319 }
279 320
280 fn() { 321 ###
281 # full name
282 python -c "import os; print os.path.realpath('$*')"
283 }
284
285 swap() {
286 # swap two files
287 if [ "$#" != "2" ]
288 then
289 echo "Usage: $FUNCNAME <file1> <file2>"
290 return
291 fi
292 for i in "$1" "$2"
293 do
294 if [ ! -w "$i" ]
295 then
296 echo "$FUNCNAME: Can't move $i"
297 return 1
298 fi
299 done
300
301 NEWNAME=`basename $1`.$RANDOM
302 while [ -e $NEWNAME ]
303 do
304 NEWNAME=${NEWNAME}.tmp
305 echo "$NEWNAME"
306 done
307
308 mv "$1" "$NEWNAME"
309 mv "$2" "$1"
310 mv "$NEWNAME" "$2"
311 }
312 322
313 buffer() { 323 buffer() {
314 # temporary buffer with cat and /dev/null 324 # temporary buffer with cat and /dev/null
315 cat > /dev/null 325 cat > /dev/null
316 } 326 }