Mercurial > hg > config
annotate .bashrc @ 816:c0638ac7fb56
add hh shortcut
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Wed, 16 Nov 2016 11:34:13 -0800 |
parents | 6beceb826eb0 |
children | 2d32115dc56c |
rev | line source |
---|---|
334
5b67dd5ce0ba
update virtualenv before upgrading
Jeff Hammel <jhammel@mozilla.com>
parents:
332
diff
changeset
|
1 #!/bin/bash |
379 | 2 |
334
5b67dd5ce0ba
update virtualenv before upgrading
Jeff Hammel <jhammel@mozilla.com>
parents:
332
diff
changeset
|
3 ### bash rc file ### |
5b67dd5ce0ba
update virtualenv before upgrading
Jeff Hammel <jhammel@mozilla.com>
parents:
332
diff
changeset
|
4 |
379 | 5 # source the profile, if it exists |
332 | 6 PROFILE=/etc/profile |
7 if [ -e "${PROFILE}" ] | |
8 then | |
9 . "${PROFILE}" | |
10 fi | |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
11 |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
12 # Test for an interactive shell. There is no need to set anything |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
13 # past this point for scp and rcp, and it's important to refrain from |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
14 # outputting anything in those cases. |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
15 if [[ $- != *i* ]] ; then |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
16 # Shell is non-interactive. Be done now! |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
17 return |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
18 fi |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
19 |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
20 # Enable colors for ls, etc. Prefer ~/.dir_colors #64489 |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
21 if [[ -f ~/.dir_colors ]] ; then |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
22 eval $(dircolors -b ~/.dir_colors) |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
23 elif [[ -f /etc/DIR_COLORS ]] ; then |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
24 eval $(dircolors -b /etc/DIR_COLORS) |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
25 fi |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
26 |
67
a791d862148c
add a default MOZCONFIG variable -- BE CAREFUL!
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
27 # variables |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
28 export BROWSER=$(which firefox) |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
29 export CLICOLOR=1 |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
30 export EDITOR='emacs -nw' |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
31 export JS_EDITLINE=1 |
510 | 32 |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
33 # aliases |
564 | 34 alias awd="python -c 'import os; print (os.path.realpath(\".\"))'" |
514 | 35 alias currentpatch='echo `hg root`/.hg/patches/`hg qapp -v | tail -n 1 | cut -f 3 -d " "`' |
246
d9b8d176c449
add a thing to get the full path to current patch and start organizing aliases
Jeff Hammel <jhammel@mozilla.com>
parents:
241
diff
changeset
|
36 alias datestamp='date +%Y%m%d%H%M%S' |
705 | 37 alias envkeys='env | sed "s/=.*//" | sort' |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
38 alias grep='grep --colour=auto' |
736 | 39 alias loopmplayer='mplayer -fixed-vo -loop 0 -fs' |
40 alias loopxine='xine -f -g -l' | |
696 | 41 alias lsenv='env | sort | less' |
697 | 42 alias mslower='mplayer -osd-fractions 1 -speed 0.1 -osdlevel 3' |
379 | 43 alias patch='patch --reject-file=-' |
769 | 44 alias random="python -c 'import sys, random; foo = sys.argv[1:]; random.shuffle(foo); print (\" \".join(foo))'" |
314 | 45 alias weekstamp="date --date=\"$((`date '+%u'`-1)) days ago\" '+%b %d'" |
250 | 46 alias wget='wget --no-check-certificate' |
535 | 47 if [ -e ~/.bashttw ] |
48 then | |
49 . ~/.bashttw | |
50 fi | |
241 | 51 |
548 | 52 # notification: from |
53 # http://www.netinfinity.org/2013/02/4/bits-and-pieces-ubuntu-terminal-notification.html | |
54 alias alert_helper='history|tail -n1|sed -e "s/^\s*[0-9]\+\s*//" -e "s/;\s*alert$//"' | |
55 alias alert='notify-send -i /usr/share/icons/gnome/32x32/apps/gnome-terminal.png "[$?] $(alert_helper)"' | |
56 | |
57 | |
66 | 58 # PROMPT |
749 | 59 PS1='# ' |
60 PS2='. ' | |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
61 PROMPT_COMMAND='echo -ne "\033]0;${SSH_CLIENT/*/$HOSTNAME:}${PWD/~/~}\007"' |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
62 |
66 | 63 # PATHs |
773 | 64 export PATH=~/firefox:~/bin:~/bin/mozilla:~/python:$PATH:/usr/sbin:/usr/games/bin:~/virtualenv:~/k0s/bin:~/docs/project/ims/workflow: |
169
ab2fc6222f94
add virtualenv to the PYTHONPATH
Jeff Hammel <jhammel@mozilla.com>
parents:
167
diff
changeset
|
65 export PYTHONPATH=~/python:$PYTHONPATH:~/virtualenv |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
66 |
759
f632a9850bb8
lookie, i can has x platform
Jeff Hammel <k0scist@gmail.com>
parents:
755
diff
changeset
|
67 # clipboard |
f632a9850bb8
lookie, i can has x platform
Jeff Hammel <k0scist@gmail.com>
parents:
755
diff
changeset
|
68 if which xclip &> /dev/null |
f632a9850bb8
lookie, i can has x platform
Jeff Hammel <k0scist@gmail.com>
parents:
755
diff
changeset
|
69 then |
f632a9850bb8
lookie, i can has x platform
Jeff Hammel <k0scist@gmail.com>
parents:
755
diff
changeset
|
70 export CLIP_COPY="xclip -i" |
f632a9850bb8
lookie, i can has x platform
Jeff Hammel <k0scist@gmail.com>
parents:
755
diff
changeset
|
71 export CLIP_PASTE="xclip -o" |
f632a9850bb8
lookie, i can has x platform
Jeff Hammel <k0scist@gmail.com>
parents:
755
diff
changeset
|
72 elif which pbcopy &> /dev/null |
f632a9850bb8
lookie, i can has x platform
Jeff Hammel <k0scist@gmail.com>
parents:
755
diff
changeset
|
73 then |
f632a9850bb8
lookie, i can has x platform
Jeff Hammel <k0scist@gmail.com>
parents:
755
diff
changeset
|
74 export CLIP_COPY="pbcopy" |
f632a9850bb8
lookie, i can has x platform
Jeff Hammel <k0scist@gmail.com>
parents:
755
diff
changeset
|
75 export CLIP_PASTE="pbpaste" |
f632a9850bb8
lookie, i can has x platform
Jeff Hammel <k0scist@gmail.com>
parents:
755
diff
changeset
|
76 else |
f632a9850bb8
lookie, i can has x platform
Jeff Hammel <k0scist@gmail.com>
parents:
755
diff
changeset
|
77 export CLIP_COPY="tee" |
f632a9850bb8
lookie, i can has x platform
Jeff Hammel <k0scist@gmail.com>
parents:
755
diff
changeset
|
78 export CLIP_PASTE="true" |
f632a9850bb8
lookie, i can has x platform
Jeff Hammel <k0scist@gmail.com>
parents:
755
diff
changeset
|
79 fi |
f632a9850bb8
lookie, i can has x platform
Jeff Hammel <k0scist@gmail.com>
parents:
755
diff
changeset
|
80 |
84 | 81 ### functions |
82 | |
695 | 83 gplot() { |
84 | |
85 gnuplot -persist <(echo plot '"'$1'"') | |
86 } | |
87 | |
349 | 88 lspath() { |
564 | 89 python -c 'import os; print ("\n".join(os.environ["PATH"].split(os.path.pathsep)))' |
349 | 90 } |
91 | |
305
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
92 apply-patch() { |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
93 # apply a patch |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
94 # TODO: |
331 | 95 # - rewrite in python! |
305
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
96 # - extract this general pattern as a bash "decorator" like `lsdiff` in .bash_overrides |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
97 # - right now level=1; make this configurable (somehow) |
331 | 98 |
305
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
99 if (( ! $# )) |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
100 then |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
101 echo "No patch supplied" |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
102 return 1 |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
103 fi |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
104 |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
105 for patch in $@ |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
106 do |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
107 if expr "$1" : 'http[s]\?://.*' &> /dev/null |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
108 then |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
109 IS_URL="true" |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
110 else |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
111 IS__URL="false" |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
112 fi |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
113 |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
114 if [[ ${IS_URL} == "true" ]] |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
115 then |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
116 if curl --location "${patch}" 2> /dev/null | (command patch -p1 --dry-run &> /dev/null) |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
117 then |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
118 curl --location "${patch}" 2> /dev/null | command patch -p1 |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
119 continue |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
120 else |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
121 echo "curl --location ${patch} 2> /dev/null | command patch -p1 --dry-run" |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
122 curl --location "${patch}" 2> /dev/null | command patch -p1 --dry-run |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
123 return $? |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
124 fi |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
125 else |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
126 if patch -p1 --dry-run < ${patch} |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
127 then |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
128 patch -p1 < ${patch} |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
129 continue |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
130 else |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
131 echo "patch -p1 --dry-run < ${patch}" |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
132 patch -p1 --dry-run < ${patch} |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
133 return $? |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
134 fi |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
135 fi |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
136 done |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
137 } |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
138 |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
139 cdwin() { |
305
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
140 # change directory to a window's location using its title, |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
141 # as that is set to the cwd by PS1 [?] |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
142 # TODO: ssh windows |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
143 DIR=$(xwininfo | dictify.py xwininfo | awk '{ print $NF }' | sed 's/"//g') |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
144 DIR=${DIR/\~/$HOME} |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
145 cd $DIR |
532 | 146 activate-nearest |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
147 } |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
148 |
66 | 149 function colors() { |
150 | |
151 CLR_WHITE="\033[0;37m" | |
152 CLR_WHITEBOLD="\033[1;37m" | |
153 CLR_BLACK="\033[0;30m" | |
154 CLR_GRAY="\033[1;30m" | |
155 CLR_BLUE="\033[1;34m" | |
156 CLR_BLUEBOLD="\033[0;34m" | |
157 CLR_GREEN="\033[0;32m" | |
158 CLR_GREENBOLD="\033[1;32m" | |
159 CLR_CYAN="\033[0;36m" | |
160 CLR_CYANBOLD="\033[1;36m" | |
161 CLR_RED="\033[0;31m" | |
162 CLR_REDBOLD="\033[1;31m" | |
163 CLR_PURPLE="\033[0;35m" | |
164 CLR_PURPLEBOLD="\033[1;35m" | |
165 CLR_YELLOW="\033[0;33m" | |
166 CLR_YELLOWBOLD="\033[1;33m" | |
167 CLR_NOTHING="\033[0m" | |
168 } | |
169 colors | |
170 | |
816 | 171 hh() { |
172 history | awk '{$1="";print substr($0,2)}' | |
173 } | |
418 | 174 |
534 | 175 ### find functionality |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
176 |
303
266d6b337373
still doesnt work but what the fuck
Jeff Hammel <jhammel@mozilla.com>
parents:
296
diff
changeset
|
177 EXCLUDES="(\.svn)|(\.mo$)|(\.po$)|(\.pyc$)|(\.hg$)|(\.git$)" |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
178 ff() { |
304
7ed290454f50
random cleanup but not much
Jeff Hammel <jhammel@mozilla.com>
parents:
303
diff
changeset
|
179 # nice fast find function |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
180 |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
181 if (( $# < 2 )) |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
182 then |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
183 FILENAME='*' # default -- look in all files |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
184 else |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
185 FILENAME=$2 |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
186 fi |
76 | 187 CMD='command find -L $PWD -iname "${FILENAME}" -print0 2> /dev/null | xargs -r0 grep -il "$1" 2> /dev/null | egrep -v "${EXCLUDES}" 2> /dev/null' |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
188 # echo $CMD |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
189 eval $CMD |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
190 |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
191 } |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
192 |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
193 chainff() { |
304
7ed290454f50
random cleanup but not much
Jeff Hammel <jhammel@mozilla.com>
parents:
303
diff
changeset
|
194 # chained fast find |
7ed290454f50
random cleanup but not much
Jeff Hammel <jhammel@mozilla.com>
parents:
303
diff
changeset
|
195 |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
196 if (( $# < 2 )) |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
197 then |
304
7ed290454f50
random cleanup but not much
Jeff Hammel <jhammel@mozilla.com>
parents:
303
diff
changeset
|
198 return 1 # bad invocation |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
199 fi |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
200 |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
201 RESULTS=`ff "$2" "$1"` |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
202 shift 2 |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
203 |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
204 for i in $RESULTS |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
205 do |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
206 for arg in $@ |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
207 do |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
208 if grep -il "$arg" "$i" &> /dev/null |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
209 then |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
210 touch /dev/null |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
211 else |
260
eacc4c5ed628
add an alias for mozbuild bugs and cleanup a bit
Jeff Hammel <jhammel@mozilla.com>
parents:
250
diff
changeset
|
212 i="" |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
213 break |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
214 fi |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
215 done |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
216 if [ -n "$i" ] |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
217 then |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
218 echo $i |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
219 fi |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
220 done |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
221 } |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
222 |
304
7ed290454f50
random cleanup but not much
Jeff Hammel <jhammel@mozilla.com>
parents:
303
diff
changeset
|
223 |
66 | 224 cff () { |
304
7ed290454f50
random cleanup but not much
Jeff Hammel <jhammel@mozilla.com>
parents:
303
diff
changeset
|
225 # contextual fastfind |
66 | 226 if (( $# < 2 )); then |
227 local FILENAME='*' # default -- look in all files | |
228 else | |
229 local FILENAME=$2 | |
230 fi | |
231 | |
232 for i in `ff "$1" "$FILENAME"`; do | |
233 echo -e "$CLR_GREEN--->>> ""$CLR_YELLOWBOLD""$i""$CLR_NOTHING" : | |
234 grep --color=auto -i -n -C 3 "$1" $i | |
235 done | |
236 | |
260
eacc4c5ed628
add an alias for mozbuild bugs and cleanup a bit
Jeff Hammel <jhammel@mozilla.com>
parents:
250
diff
changeset
|
237 } |
66 | 238 |
539 | 239 ### functions for files |
240 | |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
241 tmpfile() { |
305
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
242 # make a temporary file if `tempfile` not available |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
243 |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
244 if [ "$#" == "0" ] |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
245 then |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
246 args="tmp" |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
247 else |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
248 args=$@ |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
249 fi |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
250 |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
251 for i in $args |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
252 do |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
253 NEWNAME=${i}.$RANDOM |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
254 |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
255 while [ -e $NEWNAME ] |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
256 do |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
257 NEWNAME=${NEWNAME}.tmp |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
258 done |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
259 echo "$NEWNAME" |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
260 done |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
261 } |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
262 |
565 | 263 abspath() { |
642 | 264 # print absolute path |
565 | 265 python -c "import os; print (os.path.realpath('$*'))" |
266 } | |
267 | |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
268 fn() { |
565 | 269 # put full name on clipboard and echo it |
759
f632a9850bb8
lookie, i can has x platform
Jeff Hammel <k0scist@gmail.com>
parents:
755
diff
changeset
|
270 python -c "import os; print (os.path.realpath('$*'))" | ${CLIP_COPY} |
f632a9850bb8
lookie, i can has x platform
Jeff Hammel <k0scist@gmail.com>
parents:
755
diff
changeset
|
271 ${CLIP_PASTE} |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
272 } |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
273 |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
274 swap() { |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
275 # swap two files |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
276 if [ "$#" != "2" ] |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
277 then |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
278 echo "Usage: $FUNCNAME <file1> <file2>" |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
279 return |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
280 fi |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
281 for i in "$1" "$2" |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
282 do |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
283 if [ ! -w "$i" ] |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
284 then |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
285 echo "$FUNCNAME: Can't move $i" |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
286 return 1 |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
287 fi |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
288 done |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
289 |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
290 NEWNAME=`basename $1`.$RANDOM |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
291 while [ -e $NEWNAME ] |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
292 do |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
293 NEWNAME=${NEWNAME}.tmp |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
294 echo "$NEWNAME" |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
295 done |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
296 |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
297 mv "$1" "$NEWNAME" |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
298 mv "$2" "$1" |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
299 mv "$NEWNAME" "$2" |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
300 } |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
301 |
560 | 302 verifyfiles() { |
303 # verify each line is an existing file | |
304 while read line | |
305 do | |
306 test -e "${line}" | |
307 echo $? $line | |
308 done | |
309 } | |
539 | 310 |
311 ### functions for editing | |
312 | |
313 edpe() { | |
314 # edit and pipe the buffer to stdout | |
315 FILE=`tmpfile` | |
316 $EDITOR $FILE | |
317 cat $FILE | |
318 rm $FILE | |
319 } | |
320 | |
321 eend() { | |
322 # edit the end of a file with emacs | |
323 FILE=$1 | |
324 shift | |
325 emacs +`wc -l "$FILE"` $@ | |
326 } | |
327 | |
328 ### | |
329 | |
330 | 330 buffer() { |
331 # temporary buffer with cat and /dev/null | |
332 cat > /dev/null | |
333 } | |
334 | |
309 | 335 ### `which` commands |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
336 |
309 | 337 realwhich() { |
338 # which -> real paths | |
339 command which $@ | while read line | |
340 do | |
564 | 341 python -c "import os; print (os.path.realpath('${line}'))" |
309 | 342 done |
343 } | |
344 | |
310
a6cd6900419e
whview and whemacs use realwhich
Jeff Hammel <jhammel@mozilla.com>
parents:
309
diff
changeset
|
345 whview() { |
a6cd6900419e
whview and whemacs use realwhich
Jeff Hammel <jhammel@mozilla.com>
parents:
309
diff
changeset
|
346 # which view |
a6cd6900419e
whview and whemacs use realwhich
Jeff Hammel <jhammel@mozilla.com>
parents:
309
diff
changeset
|
347 less `realwhich $@` |
a6cd6900419e
whview and whemacs use realwhich
Jeff Hammel <jhammel@mozilla.com>
parents:
309
diff
changeset
|
348 } |
a6cd6900419e
whview and whemacs use realwhich
Jeff Hammel <jhammel@mozilla.com>
parents:
309
diff
changeset
|
349 |
a6cd6900419e
whview and whemacs use realwhich
Jeff Hammel <jhammel@mozilla.com>
parents:
309
diff
changeset
|
350 whemacs() { |
a6cd6900419e
whview and whemacs use realwhich
Jeff Hammel <jhammel@mozilla.com>
parents:
309
diff
changeset
|
351 # which emacs |
a6cd6900419e
whview and whemacs use realwhich
Jeff Hammel <jhammel@mozilla.com>
parents:
309
diff
changeset
|
352 emacs -nw `realwhich $@` |
a6cd6900419e
whview and whemacs use realwhich
Jeff Hammel <jhammel@mozilla.com>
parents:
309
diff
changeset
|
353 } |
a6cd6900419e
whview and whemacs use realwhich
Jeff Hammel <jhammel@mozilla.com>
parents:
309
diff
changeset
|
354 |
569 | 355 lswhich() { |
356 # ls -l real which | |
357 for i in "$@" | |
358 do | |
359 ls -l $(realwhich $i) | |
360 done | |
361 } | |
561 | 362 |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
363 ### functions for python |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
364 |
305
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
365 pyfile() { |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
366 # python file path |
564 | 367 python -c "import $1; print ($1.__file__)" |
305
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
368 } |
fac01a1bcedf
add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents:
304
diff
changeset
|
369 |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
370 setup-all() { |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
371 # setup all for development |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
372 # TODO: flowerbed? |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
373 for i in * |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
374 do |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
375 if [ -e "${i}/setup.py" ] |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
376 then |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
377 cd "${i}" |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
378 python setup.py develop |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
379 cd .. |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
380 fi |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
381 done |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
382 } |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
383 |
561 | 384 distribute() { |
780
c1ab43edf296
https://docs.python.org/3.1/distutils/uploading.html#pypi-package-display
Jeff Hammel <k0scist@gmail.com>
parents:
773
diff
changeset
|
385 # upload to pypi |
561 | 386 python setup.py egg_info -RDb "" sdist register upload develop |
387 } | |
388 | |
781 | 389 render_long_description() { |
780
c1ab43edf296
https://docs.python.org/3.1/distutils/uploading.html#pypi-package-display
Jeff Hammel <k0scist@gmail.com>
parents:
773
diff
changeset
|
390 # check the long_description from the command line: |
c1ab43edf296
https://docs.python.org/3.1/distutils/uploading.html#pypi-package-display
Jeff Hammel <k0scist@gmail.com>
parents:
773
diff
changeset
|
391 # https://docs.python.org/3.1/distutils/uploading.html#pypi-package-display |
c1ab43edf296
https://docs.python.org/3.1/distutils/uploading.html#pypi-package-display
Jeff Hammel <k0scist@gmail.com>
parents:
773
diff
changeset
|
392 python setup.py --long-description | rst2html.py > output.html |
c1ab43edf296
https://docs.python.org/3.1/distutils/uploading.html#pypi-package-display
Jeff Hammel <k0scist@gmail.com>
parents:
773
diff
changeset
|
393 } |
c1ab43edf296
https://docs.python.org/3.1/distutils/uploading.html#pypi-package-display
Jeff Hammel <k0scist@gmail.com>
parents:
773
diff
changeset
|
394 |
531 | 395 nearest-venv() { |
642 | 396 # find the nearest venv |
531 | 397 if [[ "$#" == "0" ]] |
398 then | |
399 directory=$PWD | |
400 else | |
401 directory=$1 | |
402 fi | |
564 | 403 directory=$(python -c "import os; print (os.path.abspath('${directory}'))") |
531 | 404 |
405 while [[ "${directory}" != "/" ]] | |
406 do | |
407 activate="${directory}/bin/activate" | |
408 if [ -e "${activate}" ] | |
409 then | |
410 echo ${directory} | |
411 return 0 | |
412 fi | |
413 | |
414 directory=$(dirname ${directory}) | |
415 | |
416 done | |
417 return 1 | |
418 } | |
419 | |
420 activate-nearest() { | |
642 | 421 # activate the nearest virtualenv |
531 | 422 nearest=$(nearest-venv) |
423 activate=${nearest}/bin/activate | |
424 if [ -e "${activate}" ] | |
425 then | |
426 . ${activate} | |
427 fi | |
428 } | |
429 | |
296 | 430 recreate-venv() { |
431 # recreate a virtualenv | |
432 VIRTUALENV="virtualenv.py" | |
334
5b67dd5ce0ba
update virtualenv before upgrading
Jeff Hammel <jhammel@mozilla.com>
parents:
332
diff
changeset
|
433 if ! which ${VIRTUALENV} |
5b67dd5ce0ba
update virtualenv before upgrading
Jeff Hammel <jhammel@mozilla.com>
parents:
332
diff
changeset
|
434 then |
5b67dd5ce0ba
update virtualenv before upgrading
Jeff Hammel <jhammel@mozilla.com>
parents:
332
diff
changeset
|
435 return 1 |
5b67dd5ce0ba
update virtualenv before upgrading
Jeff Hammel <jhammel@mozilla.com>
parents:
332
diff
changeset
|
436 fi |
651 | 437 VENV_PATH=$(which ${VIRTUALENV}) |
438 echo VENV_PATH=${VENV_PATH} | |
334
5b67dd5ce0ba
update virtualenv before upgrading
Jeff Hammel <jhammel@mozilla.com>
parents:
332
diff
changeset
|
439 |
5b67dd5ce0ba
update virtualenv before upgrading
Jeff Hammel <jhammel@mozilla.com>
parents:
332
diff
changeset
|
440 # update virtualenv if possible |
5b67dd5ce0ba
update virtualenv before upgrading
Jeff Hammel <jhammel@mozilla.com>
parents:
332
diff
changeset
|
441 DIRNAME=$(dirname ${VENV_PATH}) |
5b67dd5ce0ba
update virtualenv before upgrading
Jeff Hammel <jhammel@mozilla.com>
parents:
332
diff
changeset
|
442 if [ -d "${DIRNAME}/.git" ] |
5b67dd5ce0ba
update virtualenv before upgrading
Jeff Hammel <jhammel@mozilla.com>
parents:
332
diff
changeset
|
443 then |
5b67dd5ce0ba
update virtualenv before upgrading
Jeff Hammel <jhammel@mozilla.com>
parents:
332
diff
changeset
|
444 cd "${DIRNAME}" |
5b67dd5ce0ba
update virtualenv before upgrading
Jeff Hammel <jhammel@mozilla.com>
parents:
332
diff
changeset
|
445 git pull |
5b67dd5ce0ba
update virtualenv before upgrading
Jeff Hammel <jhammel@mozilla.com>
parents:
332
diff
changeset
|
446 cd -- |
5b67dd5ce0ba
update virtualenv before upgrading
Jeff Hammel <jhammel@mozilla.com>
parents:
332
diff
changeset
|
447 fi |
5b67dd5ce0ba
update virtualenv before upgrading
Jeff Hammel <jhammel@mozilla.com>
parents:
332
diff
changeset
|
448 |
5b67dd5ce0ba
update virtualenv before upgrading
Jeff Hammel <jhammel@mozilla.com>
parents:
332
diff
changeset
|
449 # for each virtualenv given... |
296 | 450 for i in $@ |
451 do | |
651 | 452 OLD_PWD=${PWD} |
453 echo "${i} : OLDPWD=${OLD_PWD}" | |
334
5b67dd5ce0ba
update virtualenv before upgrading
Jeff Hammel <jhammel@mozilla.com>
parents:
332
diff
changeset
|
454 # ...recreate it... |
296 | 455 ${VIRTUALENV} --clear "${i}" |
456 | |
457 SRCDIR="${i}"/src | |
458 if [ -d "${SRCDIR}" ] | |
459 then | |
460 . "${i}/bin/activate" | |
461 cd "${SRCDIR}" | |
462 for j in * | |
463 do | |
464 if [ -e "${j}"/setup.py ] | |
465 then | |
466 cd "${j}" | |
467 python setup.py develop | |
468 cd .. | |
469 fi | |
470 done | |
471 fi | |
651 | 472 echo "cd OLD_PWD=${OLD_PWD}" |
473 cd ${OLD_PWD} | |
296 | 474 done |
475 } | |
476 | |
260
eacc4c5ed628
add an alias for mozbuild bugs and cleanup a bit
Jeff Hammel <jhammel@mozilla.com>
parents:
250
diff
changeset
|
477 ### functions for version control systems |
eacc4c5ed628
add an alias for mozbuild bugs and cleanup a bit
Jeff Hammel <jhammel@mozilla.com>
parents:
250
diff
changeset
|
478 |
71
3d111401010f
add a function to view the files in a diff
Jeff Hammel <jhammel@mozilla.com>
parents:
67
diff
changeset
|
479 difffiles() { |
534 | 480 # which files are diffed; could use `lsdiff` |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
481 grep '^+++ ' $@ | sed 's/+++ b\///' |
71
3d111401010f
add a function to view the files in a diff
Jeff Hammel <jhammel@mozilla.com>
parents:
67
diff
changeset
|
482 } |
3d111401010f
add a function to view the files in a diff
Jeff Hammel <jhammel@mozilla.com>
parents:
67
diff
changeset
|
483 |
534 | 484 git-diff-master() { |
485 # differences of a git repository with master | |
486 git diff $(git merge-base HEAD master) | |
487 } | |
488 | |
489 git-diff-total() { | |
490 # diff of both added + modified files | |
491 combinediff <(git diff) <(git diff --cached) | |
492 } | |
493 | |
260
eacc4c5ed628
add an alias for mozbuild bugs and cleanup a bit
Jeff Hammel <jhammel@mozilla.com>
parents:
250
diff
changeset
|
494 hg-update-all() { |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
495 # update all hg repositories in the current directory |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
496 for i in *; |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
497 do |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
498 if [ -e $i/.hg ] |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
499 then |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
500 cd $i |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
501 hg pull |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
502 hg update |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
503 cd - |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
504 fi |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
505 done |
84 | 506 } |
507 | |
110
bf567a0e8fef
add a hg-qcommit that does the right thing
Jeff Hammel <jhammel@mozilla.com>
parents:
103
diff
changeset
|
508 hg-qcommit() { |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
509 message=$1 |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
510 hg qrefresh |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
511 if [ -z "${message}" ] |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
512 then |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
513 hg qcommit |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
514 else |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
515 hg qcommit -m "${message}" |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
516 fi |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
517 hgroot=$(hg root) |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
518 patches=${hgroot}/.hg/patches/ |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
519 if [ -e ${patches}.hg ] |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
520 then |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
521 cd ${patches} |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
522 hg push |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
523 fi |
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
524 cd - |
110
bf567a0e8fef
add a hg-qcommit that does the right thing
Jeff Hammel <jhammel@mozilla.com>
parents:
103
diff
changeset
|
525 } |
bf567a0e8fef
add a hg-qcommit that does the right thing
Jeff Hammel <jhammel@mozilla.com>
parents:
103
diff
changeset
|
526 |
89
dfda4f7d4db4
add a command to generate those hgrc files i always need
Jeff Hammel <jhammel@mozilla.com>
parents:
88
diff
changeset
|
527 |
260
eacc4c5ed628
add an alias for mozbuild bugs and cleanup a bit
Jeff Hammel <jhammel@mozilla.com>
parents:
250
diff
changeset
|
528 ### functions for web content |
eacc4c5ed628
add an alias for mozbuild bugs and cleanup a bit
Jeff Hammel <jhammel@mozilla.com>
parents:
250
diff
changeset
|
529 |
eacc4c5ed628
add an alias for mozbuild bugs and cleanup a bit
Jeff Hammel <jhammel@mozilla.com>
parents:
250
diff
changeset
|
530 blog-file() { |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
531 echo "$HOME/web/blog/k0s/entries/public/$1" |
260
eacc4c5ed628
add an alias for mozbuild bugs and cleanup a bit
Jeff Hammel <jhammel@mozilla.com>
parents:
250
diff
changeset
|
532 } |
eacc4c5ed628
add an alias for mozbuild bugs and cleanup a bit
Jeff Hammel <jhammel@mozilla.com>
parents:
250
diff
changeset
|
533 |
330 | 534 ### |
535 | |
648 | 536 apt-upgrade() { |
537 sudo apt-get -y update | |
538 sudo apt-get -y upgrade | |
539 } | |
540 | |
101 | 541 flatten() { |
542 directory=$PWD | |
543 if [ "$#" == "1" ] | |
544 then | |
545 directory=$1 | |
546 fi | |
547 cd $directory | |
548 unset find # don't use the alias | |
102 | 549 find . -name '*' -type f | sed 's/.\///' | while read line |
101 | 550 do |
551 filename=$(echo $line | sed 's/\//-/g') | |
552 mv "${line}" "${filename}" | |
553 done | |
554 for i in * | |
555 do | |
556 if [ -d $i ] | |
557 then | |
558 rm -rf "${i}" | |
559 fi | |
560 done | |
561 } | |
562 | |
103
e841c419199e
add process command to get filehandles
Jeff Hammel <jhammel@mozilla.com>
parents:
102
diff
changeset
|
563 filehandles() { |
e841c419199e
add process command to get filehandles
Jeff Hammel <jhammel@mozilla.com>
parents:
102
diff
changeset
|
564 TMPFILE=$(tmpfile) |
e841c419199e
add process command to get filehandles
Jeff Hammel <jhammel@mozilla.com>
parents:
102
diff
changeset
|
565 ps -e|grep -v TTY|awk {'print "echo -n \"Process: "$4"\tPID: "$1"\tNumber of FH: \"; lsof -p "$1"|wc -l"'} > ${TMPFILE} |
e841c419199e
add process command to get filehandles
Jeff Hammel <jhammel@mozilla.com>
parents:
102
diff
changeset
|
566 . ${TMPFILE} | sort |
e841c419199e
add process command to get filehandles
Jeff Hammel <jhammel@mozilla.com>
parents:
102
diff
changeset
|
567 rm ${TMPFILE} |
e841c419199e
add process command to get filehandles
Jeff Hammel <jhammel@mozilla.com>
parents:
102
diff
changeset
|
568 } |
e841c419199e
add process command to get filehandles
Jeff Hammel <jhammel@mozilla.com>
parents:
102
diff
changeset
|
569 |
167
842e1fca024a
add a quotemail function for quoting mail
Jeff Hammel <jhammel@mozilla.com>
parents:
147
diff
changeset
|
570 quotemail() { |
642 | 571 # TODO: -> textshaper |
167
842e1fca024a
add a quotemail function for quoting mail
Jeff Hammel <jhammel@mozilla.com>
parents:
147
diff
changeset
|
572 command='s/^/> /' |
842e1fca024a
add a quotemail function for quoting mail
Jeff Hammel <jhammel@mozilla.com>
parents:
147
diff
changeset
|
573 inplace="" |
842e1fca024a
add a quotemail function for quoting mail
Jeff Hammel <jhammel@mozilla.com>
parents:
147
diff
changeset
|
574 if [ "$#" == "2" ] |
842e1fca024a
add a quotemail function for quoting mail
Jeff Hammel <jhammel@mozilla.com>
parents:
147
diff
changeset
|
575 then |
842e1fca024a
add a quotemail function for quoting mail
Jeff Hammel <jhammel@mozilla.com>
parents:
147
diff
changeset
|
576 inplace="-i" |
842e1fca024a
add a quotemail function for quoting mail
Jeff Hammel <jhammel@mozilla.com>
parents:
147
diff
changeset
|
577 fi |
842e1fca024a
add a quotemail function for quoting mail
Jeff Hammel <jhammel@mozilla.com>
parents:
147
diff
changeset
|
578 |
842e1fca024a
add a quotemail function for quoting mail
Jeff Hammel <jhammel@mozilla.com>
parents:
147
diff
changeset
|
579 sed ${inplace} "${command}" "$1" |
842e1fca024a
add a quotemail function for quoting mail
Jeff Hammel <jhammel@mozilla.com>
parents:
147
diff
changeset
|
580 |
842e1fca024a
add a quotemail function for quoting mail
Jeff Hammel <jhammel@mozilla.com>
parents:
147
diff
changeset
|
581 } |
842e1fca024a
add a quotemail function for quoting mail
Jeff Hammel <jhammel@mozilla.com>
parents:
147
diff
changeset
|
582 |
317 | 583 rmktmp() { |
584 | |
585 TMPDIR=~/tmp | |
586 if [ -e ${TMPDIR} ] | |
587 then | |
588 rm -rf ${TMPDIR} | |
589 fi | |
590 mkdir ${TMPDIR} | |
591 cd ${TMPDIR} | |
592 pwd | |
593 | |
594 } | |
595 | |
546 | 596 exists() { |
597 while read line; do echo ${line} : $(($(test "-e ${line}"\") )); done | |
598 } | |
599 | |
767
35f8751c0930
it is very annoying to have ones overrides overridden; see also http://stackoverflow.com/questions/25381304/why-type-cd-on-mac-os-states-that-cd-is-a-function
Jeff Hammel <k0scist@gmail.com>
parents:
765
diff
changeset
|
600 ### ruby version manager |
35f8751c0930
it is very annoying to have ones overrides overridden; see also http://stackoverflow.com/questions/25381304/why-type-cd-on-mac-os-states-that-cd-is-a-function
Jeff Hammel <k0scist@gmail.com>
parents:
765
diff
changeset
|
601 [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* |
35f8751c0930
it is very annoying to have ones overrides overridden; see also http://stackoverflow.com/questions/25381304/why-type-cd-on-mac-os-states-that-cd-is-a-function
Jeff Hammel <k0scist@gmail.com>
parents:
765
diff
changeset
|
602 export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting |
35f8751c0930
it is very annoying to have ones overrides overridden; see also http://stackoverflow.com/questions/25381304/why-type-cd-on-mac-os-states-that-cd-is-a-function
Jeff Hammel <k0scist@gmail.com>
parents:
765
diff
changeset
|
603 |
0
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
604 ### include overrides for commands |
f3ab51c79813
adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
605 source ~/.bash_overrides |
47
a0636527f809
regenerate fluxbox menus on shell
Jeff Hammel <k0scist@gmail.com>
parents:
19
diff
changeset
|
606 |
742 | 607 ### deactivate any virtualenvs |
531 | 608 if type deactivate &> /dev/null |
609 then | |
610 deactivate | |
611 fi | |
649
fbfc02ea7d8e
make our menu generator slightly less vulgar
Jeff Hammel <k0scist@gmail.com>
parents:
648
diff
changeset
|
612 |
765 | 613 |
767
35f8751c0930
it is very annoying to have ones overrides overridden; see also http://stackoverflow.com/questions/25381304/why-type-cd-on-mac-os-states-that-cd-is-a-function
Jeff Hammel <k0scist@gmail.com>
parents:
765
diff
changeset
|
614 ### source site-specific BASHRC extensions |
755 | 615 export CISCO_BASHRC="${HOME}/cisco/bin/.bashrc" |
616 if [ -e "${CISCO_BASHRC}" ] | |
617 then | |
618 . "${CISCO_BASHRC}" | |
619 fi | |
620 | |
649
fbfc02ea7d8e
make our menu generator slightly less vulgar
Jeff Hammel <k0scist@gmail.com>
parents:
648
diff
changeset
|
621 ### regenerate fluxbox menus here for convenience |
47
a0636527f809
regenerate fluxbox menus on shell
Jeff Hammel <k0scist@gmail.com>
parents:
19
diff
changeset
|
622 MENU=~/web/site/programs.html |
237
b33d0c78132c
move menu regeneration to its own function
Jeff Hammel <jhammel@mozilla.com>
parents:
224
diff
changeset
|
623 regeneratefluxmenu() { |
649
fbfc02ea7d8e
make our menu generator slightly less vulgar
Jeff Hammel <k0scist@gmail.com>
parents:
648
diff
changeset
|
624 if [ -e "${MENU}" ] |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
625 then |
649
fbfc02ea7d8e
make our menu generator slightly less vulgar
Jeff Hammel <k0scist@gmail.com>
parents:
648
diff
changeset
|
626 html2flux.py "${MENU}" -o ~/.fluxbox/applications |
295
e2564dd51334
slowly slowly, step by step...
Jeff Hammel <jhammel@mozilla.com>
parents:
279
diff
changeset
|
627 fi |
237
b33d0c78132c
move menu regeneration to its own function
Jeff Hammel <jhammel@mozilla.com>
parents:
224
diff
changeset
|
628 } |
b33d0c78132c
move menu regeneration to its own function
Jeff Hammel <jhammel@mozilla.com>
parents:
224
diff
changeset
|
629 regeneratefluxmenu |