-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
316 lines (259 loc) · 8.9 KB
/
.bashrc
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
# don't put duplicate lines in the history. See bash(1) for more options
export HISTCONTROL=ignoredups
# ... and ignore same successive entries.
#export HISTCONTROL=ignoreboth
# https://stackoverflow.com/questions/12399002/how-to-configure-git-bash-command-line-completion
# https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
if [ -f /etc/bash_completion.d/git ]; then
source /etc/bash_completion.d/git
fi
set -o vi
set -o noclobber
#-----------------------------------
# Portable Aliases
#-----------------------------------
alias rm='rm -i'
alias mv='mv -i'
alias cp='cp -i'
alias grepc='grep -i --color=auto'
alias grep='grep -i'
alias l='ls -lh'
alias ll='ls -lh'
alias ls='ls -HGF'
alias la='ls -a'
alias lla='ll -a'
alias lr='ls -R'
alias md='mkdir -p'
alias ...='cd ../..'
alias ....='cd ../../..'
alias h='history'
alias whereami='curl -s http://api.hostip.info/get_html.php?ip=$1'
alias path='echo -e ${PATH//:/\\n}'
alias vi=vim
alias edit='vim'
alias svi='sudo vi'
alias ports='netstat -tulap tcp'
alias durev='du -s * | sort -rn'
alias httpdreload='sudo /usr/sbin/apachectl -k graceful'
alias psync='auto_rsync -n aws-project -s 0.2 -l -w ~/PycharmProjects/project/project -u user -r aws-project:/<root-path>/project/project'
alias psynck='auto_rsync -n aws-project --unload'
alias sshp='ssh user@aws-project'
#-----------------------------------
# OS X Aliases
#-----------------------------------
alias psmem='ps aux | sort -nr -k 4'
alias pscpu='ps aux | sort -nr -k 3'
# Top 10 memory and CPU consuming processes. Good for Geektool. On Linux, use auxf.
alias psmem10='ps aux | sort -nr -k 4 | head -10'
alias pscpu10='ps aux | sort -nr -k 3 | head -10'
# a less cpu intensive top. BSD-specific?
alias ttop='top -ocpu -R -F -s 2 -n30'
# Miscellaneous commands
alias spot='mdfind -onlyin `pwd`'
# Delete all .DS_Store files in current dir and its children
alias ds_store_rm='find . -name '.DS_Store' -print0 | xargs -t0 rm'
#-----------------------------
# Machine Specific Functions
# i.e., may require additional setup of MySQL, Python, Java, etc.
#-----------------------------
# Log SQL statements. If local MySQL, you must connect with --protocol=tcp. Assumes Wireshark installed.
alias mysqllog="sudo tshark -i lo0 -V -f 'dst port 3306' | egrep 'Statement:|Statement \[truncated\]:'"
# Start and stop MySQL
alias mysql_start="/Library/StartupItems/MySQLCOM/MySQLCOM start"
alias mysql_stop="/Library/StartupItems/MySQLCOM/MySQLCOM stop"
alias sock='ln -s /opt/local/var/run/mysql5/mysqld.sock /tmp/mysql.sock'
#-----------------------------------
# Portable Functions
#-----------------------------------
# cd's up directory path by the specified number of levels. Defaults to 1.
function ..() {
local arg=${1:-1};
while [ $arg -gt 0 ]; do
cd .. >&/dev/null;
arg=$(($arg - 1));
done
}
# Usage:
# $ some_command ; notify
# After the command finishes, email is sent to space-delimited list of email addresses in mail variable
# Especially useful if you use a mobile carrier address that sends you a text message
# For example, nnnnnnnnnn@messaging.sprintpcs.com
function notify() {
# NOTE!!! Set mail var to desired list of email addresses.
mail="rstewart@castlighthealth.com 5102903391@messaging.sprintpcs.com"
str1="`history 1 | cut -b 8-`"
str2="${str1%;*}"
echo ${str2} | mail -s CMD_FINISH ${mail}
}
# bash function to decompress archives - http://www.shell-fu.org/lister.php?id=375
function extract() {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.txz) tar xfJ $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via >extract<" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
#-------------------------
# OS X Specific Functions
#-------------------------
# Define colors for custom prompt
#red='\[\e[0;31m\]'
#RED='\[\e[1;31m\]'
#blue='\[\e[0;34m\]'
#BLUE='\[\e[1;34m\]'
#cyan='\[\e[0;36m\]'
#CYAN='\[\e[1;36m\]'
#NC='\[\e[0m\]' # No Color
function customprompt() {
# Set the window title to user, host and relative path (Use \W for full path)
TITLE="\u@\h: \w"
# \[...\] tells bash to ignore non-printing control characters when calculating prompt width.
# Otherwise, line editing commands get confused while placing the cursor.
LINE_PROMPT="${cyan}\u@\h:\w\n${red}[\!] \$ ${NC}"
# Set up PS1 to do the window title and line prompt
case $TERM in
xterm*)
PS1="\[\033]0;$TITLE\007\]$LINE_PROMPT"
;;
*)
PS1="$LINE_PROMPT"
;;
esac
}
# Set custom prompt
customprompt
# Open man page in TextMate.
# arg1 = command name
function mateman() {
MANWIDTH=160 MANPAGER='col -bx' man $@ | mate
}
# Quit OS X apps from command line.
# vararg = app names
function quit() {
for app in $*; do
osascript -e 'quit app "'$app'"'
done
}
# Relaunch OS X apps from command line.
# vararg = app names
function relaunch() {
for app in $*; do
osascript -e 'quit app "'$app'"';
sleep 3;
open -a $app
done
}
# spotlight powered locate
function slocate() {
mdfind "kMDItemDisplayName == '$@'wc";
}
# cd's to frontmost window of Finder
function cdf() {
cd "`osascript -e 'tell application "Finder"' \
-e 'set myname to POSIX path of (target of window 1 as alias)' \
-e 'end tell' 2>/dev/null`"
}
# Moves files to trash, rather than immediately deleting them
function trash () {
local path
for path in "$@"; do
# ignore any arguments
if [[ "$path" = -* ]];
then :
else local dst=${path##*/}
# append the time if necessary
while [ -e ~/.Trash/"$dst" ]; do
dst="$dst "$(date +%H-%M-%S)
done
mv "$path" ~/.Trash/"$dst"
fi
done
}
#-----------------------------
# Machine Specific Functions
# i.e., may require additional setup of MySQL, Python, Java, Git, etc.
#-----------------------------
# Return list of queries actually executing on a MySQL server
# arg1 = user
# arg2 = host, will use localhost if omitted
function dbq() {
echo "SHOW PROCESSLIST" | mysql -u $1 -h ${2:-localhost} -p -t | grep -E "(^\| Id|^\+|Query)"
}
function find_git_branch_new {
git_branch=git branch 2> /dev/null |grep '*'|sed 's/../[/;s/$/]/'
}
function find_git_branch {
local dir=. head
until [ "$dir" -ef / ]; do
if [ -f "$dir/.git/HEAD" ]; then
head=$(< "$dir/.git/HEAD")
if [[ $head == ref:\ refs/heads/* ]]; then
git_branch="[${head##*/}]"
elif [[ $head != '' ]]; then
git_branch='[detached]'
else
git_branch='[unknown]'
fi
return
fi
dir="../$dir"
done
git_branch=''
}
BLACK='\[\e[0;30m\]'
GREEN='\[\e[0;32m\]'
source ~/.bash_prompt
# Show all git branches by last modified date
# > recent_branches
function recent_branches() {
for k in `git branch -r|perl -pe s/^..//`;do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k|head -n 1`\\t$k;done|sort
}
# Pretty prints JSON from one file to another, or to stdout
# arg1 = file name with ugly JSON
# arg2 = file name to which to write pretty JSON. If none specified, write to stdout.
function prettyjson() {
if [ "$2" != "" ]; then
cat $1 | python -mjson.tool > $2
else
cat $1 | python -mjson.tool 2>&1
fi
}
# alias to get back the pylint error codes
alias pylint='pylint --msg-template "{msg_id}:{line:3d},{column}: {obj}: {msg}"'
alias pylint_no_todo='pylint -d W0511 --msg-template "{msg_id}:{line:3d},{column}: {obj}: {msg}"'
alias nose='nosetests omicia_pipeline integration_tests'
alias noseq='nosetests omicia_pipeline integration_tests 2>&1 |grep -v "^omicia_pipeline"'
alias nosevq='nosetests omicia_pipeline integration_tests 2>&1 |egrep -v "^([a-z =>]|[A-Z][a-z]|$|\-)"'
# ls with colors!
export CLICOLOR=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
if [ -f $HOME/.iterm2_shell_integration.bash ]; then
source $HOME/.iterm2_shell_integration.bash
fi
alias ut='ssh spiro@xserver.math.utah.edu'
alias diff='git diff --no-index'
alias s3lb='aws s3 ls'
function s3grep() {
aws s3 ls s3://$1 --recursive | grep $2
}
alias ppath='export PYTHONPATH=.'
alias tfplanless='terraform plan -no-color | less'
alias tfplanrefresh='terraform plan -refresh-only'