-
Notifications
You must be signed in to change notification settings - Fork 0
/
aliases
360 lines (306 loc) · 10.2 KB
/
aliases
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# some more ls aliases
alias ll='ls -al'
alias la='ls -A'
alias l='less'
alias h='history'
alias n='nvim'
alias pu=pushd
alias po=popd
function ssftp {
(unset SSH_AUTH_SOCK; sftp $@)
}
function randomise {
echo ${1:-{A..Z}} | tr -d ' ' | fold -w 1 | sort --random-sort;
}
# Django
alias pm='python $([ -e manage.py ] && echo manage.py || echo */manage.py)'
alias pmr='pm runserver_plus'
alias pms='pm shell_plus'
# Set up DB tunnel to Sultan
alias sshtunnel='ssh [email protected] -L 9432:localhost:5432'
# Update DATABASE_URL to use 127.0.0.1:9432
alias dbtunnel='export DATABASE_URL=$(echo $DATABASE_URL|sed -e "s/192.168.0.2/127.0.0.1:9432/")'
# Set up AFP tunnel to Sultan (for finder)
alias afptunnel='ssh [email protected] -L 5480:192.168.0.3:548 -N -f && open afp://[email protected]:5480/Clients'
# Set env using hoard
alias setenv='$(hoard get | sed s/^/export\ /)'
alias junglediskload='sudo launchctl load -w /Library/LaunchDaemons/com.jungledisk.service.plist'
alias junglediskunload='sudo launchctl unload -w /Library/LaunchDaemons/com.jungledisk.service.plist'
alias builddocx='for file in docs/src/*.md; do pandoc -s -S $file -o docs/docx/$(basename ${file%%.*}).docx; done'
# Git utils
alias git-delete-merged='git branch --merged| egrep -v "^\*|master|main|dev$" | xargs git branch -d'
function git-authors {
git log --format='%aN' | sort -u
}
function gitstat-author {
git log --all --author="${1}" --after=`date -v-${2-7}d "+%Y-%m-%d"` --pretty=tformat: --numstat | \
awk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s removed lines : %s total lines: %s\n",add,subs,loc }' -
}
function gitstat-authors {
git-authors | while read author; do
echo "$author"
echo " "$(gitstat-author "$author" $@)
done
}
# ssh to a local machine (pass in the last part of the machines ip)
# Use sslocal 7 for ssh [email protected]
function sslocal
{
if [[ "${1}" ]] ; then
ssh ${2:-incuna}@192.168.0.$1
else
echo "Host number not specified";
echo "Usage sslocal <machine number> [user]";
fi
}
function svnaddall
{
svn status $@ | egrep '^\?' | sed -e 's/^\?\s*//' | xargs svn add
}
function stat {
cwd=`pwd`;
for dir in ${@:-./src/*}; do
if [ -d "$dir" ] ; then
cd $dir;
echo "Status for $dir";
if [ -e .svn ]; then svn st; fi;
if [ -e .hg ]; then hg status; fi;
if [ -e .git ]; then git status; fi;
cd $cwd;
fi
done;
}
function incoming {
cwd=`pwd`;
for dir in ${@:-./src/*}; do
if [ -d "$dir" ] ; then
cd $dir;
echo "Incoming for $dir";
if [ -e .svn ]; then svn st -u; fi;
if [ -e .hg ]; then hg incoming; fi;
if [ -e .git ]; then git fetch && git log ..origin/master; fi;
cd $cwd;
fi
done;
}
function update {
cwd=`pwd`;
for dir in ${@:-./src/*}; do
if [ -d "$dir" ] ; then
cd $dir;
echo "Updating $dir";
if [ -e .svn ]; then svn update; fi;
if [ -e .hg ]; then hg fetch; fi;
if [ -e .git ]; then git pull; fi;
cd $cwd;
fi
done;
}
function bitbucketadd {
BITBUCKET_ACOUNT=incuna
PROJECT_NAME=$1
IS_PRIVATE=${2:-true}
BITBUCKET_USER=${3:-incuna:$BITBUCKET_PASSWORD}
echo "Adding the project to bitbucket."
curl -s -u "${BITBUCKET_USER}" 'https://api.bitbucket.org/1.0/repositories/' -X POST -d "name=${PROJECT_NAME}&is_private=${IS_PRIVATE}"
}
function bitbucketaddpermissions {
BITBUCKET_ACOUNT=incuna
BITBUCKET_USER=${2:-incuna:$BITBUCKET_PASSWORD}
PROJECT_NAME=$1
if [ "${PROJECT_NAME}" == "" ] ; then
export REPOS=`curl -u "${BITBUCKET_USER}" "https://api.bitbucket.org/1.0/users/${BITBUCKET_ACOUNT}/"`
# Parse permissions (json) using python
python -c "from json import loads" > /dev/null 2>&1
if [ $? != 0 ] ; then
echo "python module json not found"
else
SLUGS=`python -c "
from os import environ
from json import loads
repos = loads(environ['REPOS'])
if 'repositories' in repos:
for p in repos['repositories']:
print p['slug']"`;
for SLUG in $SLUGS; do
bitbucketaddpermissions $SLUG
done
return 0
fi
fi
# user permissions
export PERMS=`curl -u "${BITBUCKET_USER}" "https://api.bitbucket.org/1.0/privileges/${BITBUCKET_ACOUNT}/incuna-project/"`;
# Parse permissions (json) using python
python -c "from json import loads" > /dev/null 2>&1
if [ $? != 0 ] ; then
echo "python module json not found"
else
PRIVILEGES=`python -c "
from os import environ
from json import loads
for p in loads(environ['PERMS']): print '%s:%s' % (p['user']['username'], p['privilege'])"`;
echo "Adding user permission."
for PAIR in $PRIVILEGES; do
USER=${PAIR%:*}
PRIVILEGE=${PAIR#*:}
if [ $USER == $PRIVILEGE ]; then
PRIVILEGE='write';
fi
echo " $USER > $PRIVILEGE"
bitbucketaddpermission $PROJECT_NAME $USER $PRIVILEGE
done
fi
# group permissions
export PERMS=`curl -u "${BITBUCKET_USER}" "https://api.bitbucket.org/1.0/group-privileges/incuna/incuna-project/"`;
# Parse permissions (json) using python
python -c "from json import loads" > /dev/null 2>&1
if [ $? != 0 ] ; then
echo "python module json not found"
else
PRIVILEGES=`python -c "
from os import environ
from json import loads
for p in loads(environ['PERMS']): print '%s:%s' % (p['group']['slug'], p['privilege'])"`;
echo "Adding group permission."
for PAIR in $PRIVILEGES; do
USER=${PAIR%:*}
PRIVILEGE=${PAIR#*:}
if [ $USER == $PRIVILEGE ]; then
PRIVILEGE='write';
fi
echo " $USER > $PRIVILEGE"
bitbucketaddgrouppermission $PROJECT_NAME $USER $PRIVILEGE
done
fi
}
function bitbucketaddprivilege {
BITBUCKET_ACOUNT=incuna
BITBUCKET_USER=${5:-incuna:$BITBUCKET_PASSWORD}
TYPE=${4:-privileges}
PERMISSION=${3:-write}
WHAT=$2
PROJECT_NAME=$1
echo "https://api.bitbucket.org/1.0/${TYPE}/${BITBUCKET_ACOUNT}/${PROJECT_NAME}/${WHAT}" -d $PERMISSION
curl -s -u -X PUT "$BITBUCKET_USER" "https://api.bitbucket.org/1.0/${TYPE}/${BITBUCKET_ACOUNT}/${PROJECT_NAME}/${WHAT}" -d $PERMISSION
}
function bitbucketaddpermission {
BITBUCKET_ACOUNT=incuna
BITBUCKET_USER=${4:-incuna:$BITBUCKET_PASSWORD}
PERMISSION=${3:-write}
USER=$2
PROJECT_NAME=$1
curl -s -X PUT -u "$BITBUCKET_USER" "https://api.bitbucket.org/1.0/privileges/$BITBUCKET_ACOUNT/$PROJECT_NAME/$USER" -d $PERMISSION
#bitbucketaddprivilege $1 $2 ${3:-write} 'privileges' $4
}
function bitbucketaddgrouppermission {
BITBUCKET_ACOUNT=incuna
BITBUCKET_USER=${4:-incuna:$BITBUCKET_PASSWORD}
PERMISSION=${3:-write}
GROUP=$2
PROJECT_NAME=$1
curl -s -X PUT -u "$BITBUCKET_USER" "https://api.bitbucket.org/1.0/group-privileges/$BITBUCKET_ACOUNT/$PROJECT_NAME/$BITBUCKET_ACOUNT/$GROUP" -d $PERMISSION
#bitbucketaddprivilege $1 $2 ${3:-write} 'group-privileges' $4
}
alias activate='source bin/activate'
alias virtualenvactivate='(virtualenv --no-site-packages .) && activate'
alias activatebuildout='virtualenvactivate && (bin/python bootstrap.py) && (bin/buildout -N)'
function rebuildvirtualenv {
project=${1}
python=${2:-$(which python)}
workon ${project}
deactivate
rmvirtualenv ${project}
mkvirtualenvv ${python} ${project}
setvirtualenvproject
pip install -r requirements.txt
}
function mkvirtualenvv {
python=${1:-python}
name=${2:-$(basename $(pwd))}
mkvirtualenv ${name} --python=$(which ${python})
setvirtualenvproject
}
alias mkvirtualenv3='mkvirtualenvv python3'
alias workon.='workon $(basename $(pwd))'
function key-share {
if [ "${1}" == "" ] ; then
echo "Host not specified";
echo "Usage key-share [user]@[host]";
return 1
fi
host=${1}
echo "${host}" | grep -q "@"
if [ $? == 1 ] ; then
host="incuna@${host}"
fi
cat ~/.ssh/id_rsa.pub | ssh ${host} 'cat - >> ~/.ssh/authorized_keys'
}
function update-keys {
usage="Usage update-keys [key_file] [user]@[host1] ...";
if [ "${1}" == "" ] ; then
echo "File not specified";
echo ${usage};
return 1
fi
key_file=${1}; shift;
if [ "${1}" == "" ] ; then
echo "Host not specified";
echo $usage;
return 1
fi
for host in $@; do
echo "${host}" | grep -q "@"
if [ $? == 1 ] ; then
host="incuna@${host}"
fi
echo "${key_file} | ssh ${host} 'cat - > ~/.ssh/authorized_keys'"
cat ${key_file} | ssh ${host} 'cat - > ~/.ssh/authorized_keys'
done
}
function release {
user=${1:-incuna}
python setup.py register -r $user sdist upload -r $user
}
function sgrep
{
grep $@ | egrep -v '(.svn|.pyc)'
}
# Synopsis planning tool build
function cpt_build
{
if [ "$1" == "" ] ; then
echo "No customer"
return 1
fi
ant -Dcustomer=$1 deploy_customer
}
function cpt_release
{
if [ "$1" == "" ] ; then
echo "No customer"
return 1
fi
ant -Dcustomer=$1 release_customer
}
djvim() {
mvim "+cd $1" "+TlistAddFilesRecursive . [^_]*py\|*js\|*html\|*css" +TlistOpen
}
changelog() {
last=''
while IFS= read -r first; do
while read tag; do
echo
echo "## ${last:-CURRENT}"
echo
while read number; do
echo "* #$number $(gh pr view "$number" | head -n 1 | sed -e 's/^title:\t//')"
done < <(git log --merges "$last...$tag" --pretty=format:"%s" --reverse | \
grep '^Merge pull request' | \
sed -e 's/^Merge pull request #\([0-9]*\).*$/\1/')
last=$tag
done < <(git tag | grep "^$first" | sort -r -t . -k 2 -n)
done < <(git tag | grep '^\(v2\|deploy\)' | sort -u -r)
}
# Convert file to utf8 using vim
alias utf8='vim +"set nobomb | set fenc=utf8 | x"'
alias password='base64 < /dev/random | tr -dc _a-z-0-9 | head -c24'