comparison .bashrc @ 305:fac01a1bcedf

add an apply-patch function
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 14 May 2013 18:29:24 -0700
parents 7ed290454f50
children 6095d439d1f2
comparison
equal deleted inserted replaced
304:7ed290454f50 305:fac01a1bcedf
51 export PATH=~/firefox:~/bin:~/python:$PATH:/usr/sbin:/usr/games/bin 51 export PATH=~/firefox:~/bin:~/python:$PATH:/usr/sbin:/usr/games/bin
52 export PYTHONPATH=~/python:$PYTHONPATH:~/virtualenv 52 export PYTHONPATH=~/python:$PYTHONPATH:~/virtualenv
53 53
54 ### functions 54 ### functions
55 55
56 apply-patch() {
57 # apply a patch
58 # TODO:
59 # - extract this general pattern as a bash "decorator" like `lsdiff` in .bash_overrides
60 # - right now level=1; make this configurable (somehow)
61 if (( ! $# ))
62 then
63 echo "No patch supplied"
64 return 1
65 fi
66
67 for patch in $@
68 do
69 if expr "$1" : 'http[s]\?://.*' &> /dev/null
70 then
71 IS_URL="true"
72 else
73 IS__URL="false"
74 fi
75
76 if [[ ${IS_URL} == "true" ]]
77 then
78 if curl --location "${patch}" 2> /dev/null | (command patch -p1 --dry-run &> /dev/null)
79 then
80 curl --location "${patch}" 2> /dev/null | command patch -p1
81 continue
82 else
83 echo "curl --location ${patch} 2> /dev/null | command patch -p1 --dry-run"
84 curl --location "${patch}" 2> /dev/null | command patch -p1 --dry-run
85 return $?
86 fi
87 else
88 if patch -p1 --dry-run < ${patch}
89 then
90 patch -p1 < ${patch}
91 continue
92 else
93 echo "patch -p1 --dry-run < ${patch}"
94 patch -p1 --dry-run < ${patch}
95 return $?
96 fi
97 fi
98 done
99 }
100
56 cdwin() { 101 cdwin() {
57 # change directory to a window's location using its title 102 # change directory to a window's location using its title,
103 # as that is set to the cwd by PS1 [?]
104 # TODO: ssh windows
58 DIR=$(xwininfo | dictify.py xwininfo | awk '{ print $NF }' | sed 's/"//g') 105 DIR=$(xwininfo | dictify.py xwininfo | awk '{ print $NF }' | sed 's/"//g')
59 DIR=${DIR/\~/$HOME} 106 DIR=${DIR/\~/$HOME}
60 cd $DIR 107 cd $DIR
61 } 108 }
62 109
154 grep --color=auto -i -n -C 3 "$1" $i 201 grep --color=auto -i -n -C 3 "$1" $i
155 done 202 done
156 203
157 } 204 }
158 205
159 # make a temporary file if `tempfile` not available
160 tmpfile() { 206 tmpfile() {
207 # make a temporary file if `tempfile` not available
161 208
162 if [ "$#" == "0" ] 209 if [ "$#" == "0" ]
163 then 210 then
164 args="tmp" 211 args="tmp"
165 else 212 else
204 fn() { 251 fn() {
205 # full name 252 # full name
206 python -c "import os; print os.path.realpath('$*')" 253 python -c "import os; print os.path.realpath('$*')"
207 } 254 }
208 255
209 pyfile() {
210 # python file name
211 python -c "import $1; print $1.__file__"
212 }
213
214 swap() { 256 swap() {
215 # swap two files 257 # swap two files
216 if [ "$#" != "2" ] 258 if [ "$#" != "2" ]
217 then 259 then
218 echo "Usage: $FUNCNAME <file1> <file2>" 260 echo "Usage: $FUNCNAME <file1> <file2>"
249 # which emacs 291 # which emacs
250 emacs -nw `which $@` 292 emacs -nw `which $@`
251 } 293 }
252 294
253 ### functions for python 295 ### functions for python
296
297 pyfile() {
298 # python file path
299 python -c "import $1; print $1.__file__"
300 }
254 301
255 setup-all() { 302 setup-all() {
256 # setup all for development 303 # setup all for development
257 # TODO: flowerbed? 304 # TODO: flowerbed?
258 for i in * 305 for i in *