-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbash_profile
388 lines (315 loc) · 9.59 KB
/
bash_profile
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# my custom bash env
# first, detect if we're mac or what
# found snippets of this on stackoverflow
unameish="$(uname -s)"
case "${unameish}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
CYGWIN*) machine=Cygwin;;
*) machine="UNKNOWN:${unameOut}"
esac
# anything rc?
if [ -e $HOME/.bashrc ]; then
source $HOME/.bashrc
fi
if [ -e $HOME/.env ]; then
source $HOME/.env
fi
alias wthr="curl 'wttr.in/~cedar+park,tx?un1'"
function mcd {
dest=$1
if [ -z $dest ]; then
newdt=`date "+%Y%M%d"`
dest=`echo tmpdir-${newdt}-${RANDOM}`
fi
mkdir -p $dest
cd $dest
}
# get our personal helpers
LOCALBIN="~/.localbin"
export PATH=$LOCALBIN:$PATH:$HOME/.bin
export PATH=$LOCALBIN:$HOME/.bin:/opt/homebrew/bin:$PATH
# get me some vim cmd line luvin
set -o vi
# api keys, etc
if [ -e $HOME/.secrets/secrets ]; then
source $HOME/.secrets/secrets
fi
if [ -e $HOME/.bash_local ]; then
source $HOME/.bash_local
fi
# export PYTHONSTARTUP=$HOME/.pythonrc.py
# git related shellery
export GIT_PS1_SHOWDIRTYSTATE=1
source ~/.scriptdir/git-completion.bash
prompt_command() {
local BLACK="\[\033[0;30m\]"
local RED="\[\033[0;31m\]"
local GREEN="\[\033[0;32m\]"
local YELLOW="\[\033[0;33m\]"
local BLUE="\[\033[0;34m\]"
local MAGENTA="\[\033[0;35m\]"
local CYAN="\[\033[0;36m\]"
local WHITE="\[\033[0;37m\]"
local BBLACK="\[\033[1;30m\]"
local BGREEN="\[\033[1;32m\]"
local BMAGENTA="\[\033[1;35m\]"
local BCYAN="\[\033[1;36m\]"
local BWHITE="\[\033[1;37m\]"
local DARKGRAY="\[\033[01;34m\]"
local BOLDGRAY="\[\033[01;31m\]"
local DEFAULT="\[\033[0;39m\]"
if [ $(type -t __git_ps1) ]; then
local BRANCH="$( __git_ps1 "(%s)" )"
fi
if [ $UID == 0 ];then
local PROMPT_ROOT="${RED}\h${DEFAULT}"
local PROMPT_C="#"
else
local PROMPT_ROOT="\h"
local PROMPT_C="\$" # but shouldn't this replace if root? yes.. sigh.
# but there were certain instances where this character wasn't getting
# replaced properly
fi
export PS1='${PROMPT_ROOT}:${DARKGRAY}\W${BOLDGRAY}$(type -t __git_ps1>/dev/null && __git_ps1 "(%s)")${DEFAULT}\$ ' # user
}
# PROMPT_COMMAND=prompt_command
# set up the prompt for the right context
# changes hostname to red if root
export PS1='$( if [ $UID != 0 ]; then echo -n "\[\033[01;32m\]" ; else echo -n "\[\033[0;31m\]"; fi )\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[01;31m\]$(typeset -f __git_ps1>/dev/null && __git_ps1 "(%s)")\[\033[00m\]\$ ' # user
alias sr="sudo bash --login "
alias hil='egrep -e"" --color=auto -e'
alias rs='rsync -a --progress --partial'
alias nth='open -a Terminal.app .'
# Setup some colors to use later in interactive shell or scripts
export COLOR_NONE='\e[0m' # No Color
export COLOR_WHITE='\e[1;37m'
export COLOR_BLACK='\e[0;30m'
export COLOR_BLUE='\e[0;34m'
export COLOR_LIGHT_BLUE='\e[1;34m'
export COLOR_GREEN='\e[0;32m'
export COLOR_LIGHT_GREEN='\e[1;32m'
export COLOR_CYAN='\e[0;36m'
export COLOR_LIGHT_CYAN='\e[1;36m'
export COLOR_RED='\e[0;31m'
export COLOR_LIGHT_RED='\e[1;31m'
export COLOR_PURPLE='\e[0;35m'
export COLOR_LIGHT_PURPLE='\e[1;35m'
export COLOR_BROWN='\e[0;33m'
export COLOR_YELLOW='\e[1;33m'
export COLOR_GRAY='\e[1;30m'
export COLOR_LIGHT_GRAY='\e[0;37m'
export CLICOLOR=1
export GREP_COLOR=$COLOR_RED
alias colorslist="set | egrep 'COLOR_\w*'" # Lists all colors
alias l="ls -lrtF"
alias ll="ls -lF"
alias scratch="source ~/.scratch/bin/activate"
# pip command line completion is nice too
# which pip >/dev/null 2>&1 && eval "`pip completion --bash`"
# pip bash completion start
_pip_completion()
{
COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \
COMP_CWORD=$COMP_CWORD \
PIP_AUTO_COMPLETE=1 $1 ) )
}
complete -o default -F _pip_completion pip
# pip bash completion end
# A bash completion script for Fabric targets
# Author: Michael Dippery <mdippery@gmail.com>
_complete_fabric() {
COMPREPLY=()
if [ -e ./fabfile.py ]; then
local targets=$(grep 'def [a-z].*' ./fabfile.py | sed -e 's/^def //g' -e 's/(.*)://g')
local cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "${targets}" -- ${cur}) )
fi
}
complete -o bashdefault -o default -F _complete_fabric fab
# set my timezone to central
export TZ=CST6CDT
# #######################################
# OSX related aliases
# #######################################
export APPLESCRIPT_DIR=$HOME/.applescripts
# itunes related aliases
alias np="osascript ${APPLESCRIPT_DIR}/nowplaying.osa"
alias npp="osascript ${APPLESCRIPT_DIR}/nowplaying.osa|pbcopy && pbpaste"
alias nph="osascript ${APPLESCRIPT_DIR}/nphermes.osa|pbcopy && pbpaste"
alias vmax="osascript ${APPLESCRIPT_DIR}/term_max_height.osa"
function mkdt() {
dt=`date +%y%m%d`
mkdir -p $dt
cd $dt
}
function tardt() {
d=`basename $1`
dt=`date +%y%m%d`
outname="${d}.${dt}.tgz"
tar czf $outname $d
[ -e $outname ] && echo $outname
}
function human() {
val=$1
thousand=1000
million=1000000
billion=1000000000
trillion=1000000000000
# add commas to numeric strings, changing "1234567" to "1,234,567"
commaized=`echo $val | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'`
scale=$trillion
name_scale="trillion"
shorter=`bc <<< "scale=2; $val / $scale"`
if [[ ( $shorter > 0 ) ]] ; then
echo $shorter $name_scale or $commaized
return
fi
scale=$billion
name_scale="billion"
shorter=`bc <<< "scale=2; $val / $scale"`
if [[ ( $shorter > 0 ) ]] ; then
echo $shorter $name_scale or $commaized
return
fi
scale=$million
name_scale="million"
shorter=`bc <<< "scale=2; $val / $scale"`
if [[ ( $shorter > 0 ) ]] ; then
echo $shorter $name_scale or $commaized
return
fi
scale=$thousand
name_scale="thousand"
shorter=`bc <<< "scale=2; $val / $scale"`
if [[ ( $shorter > 0 ) ]] ; then
echo $shorter $name_scale or $commaized
return
fi
echo failed probably... $commaized
}
function sotd() {
songpath=`osascript ${APPLESCRIPT_DIR}/sotd.osa`
shortpath=${songpath##*/}
echo "Be patient... uploading: ${shortpath} " >&2
tmp33 "${songpath}"
}
# give me a "show info" from teh cmd line
alias i="osascript ${APPLESCRIPT_DIR}/info.osa > /dev/null 2>&1"
alias irc="ssh -t ${IRCHOST} screen -rd irc"
# pip bash completion start
_pip_completion()
{
COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \
COMP_CWORD=$COMP_CWORD \
PIP_AUTO_COMPLETE=1 $1 ) )
}
complete -o default -F _pip_completion pip
# pip bash completion end
# virtualenv
vw=`which virtualenvwrapper.sh 2>/dev/null`
if [[ -n "$vw" ]] ; then
export WORKON_HOME=$HOME/Work/virtualenv
export PIP_RESPECT_VIRTUALENV=true
export PIP_VIRTUALENV_BASE=$WORKON_HOME
source "$vw"
fi
# helpers from troy on working with github pull reqs
function delp {
# delete git pull request branch
br=$(git branch | awk '$1=="*" {print $2; exit}')
if ! echo "$br" | egrep -q '^pull-[0-9]+$'; then
echo "\"$br\" is not a pull request branch" >&2
return 1
fi
git checkout master
git branch -D "$br"
}
function gitdir_top {
w=$(git rev-parse --git-dir)
if [[ -n $w ]] ; then
echo "$w/.."
fi
}
function git_upstream {
# which remote name represents the current repo's upstream
# if there's one named "upstream" pick that one, otherwise, default
# to "origin".
git remote | fgrep upstream || echo origin
}
function pullr {
# pullr : run tests against a pull request
# given a pull request number, merge the pull request with master,
# and run testcases. when finished, if all tests pass, optionally
# remove the pull request branch.
pullreq=${1?}
delpull=$2 # any value deletes pull request branch on passed tests
(cd $(gitdir_top) && # git pulls has to be done at the top
git co master && # make sure we're on master
git pull $(git_upstream) master && # make sure we're up-to-date
git pulls update &&
gh fetch-pull $pullreq merge &&
fab test)
rc=$?
if [[ $rc -eq 0 ]] && [[ -n "$delpull" ]] ; then
delp
rc=$?
fi
return $rc
}
function hx() {
hexdump -C $1 | less
}
function moff() {
open -a Markoff "$1"
}
# anything local only?
if [ -e $HOME/.bash_local ]; then
source $HOME/.bash_local
fi
# wonk with jupyter in virtualenvs on osx
function frameworkpython {
if [[ ! -z "$VIRTUAL_ENV" ]]; then
PYTHONHOME=$VIRTUAL_ENV /usr/bin/python "$@"
else
/usr/bin/python "$@"
fi
}
export GOPATH=$HOME/Work/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
function myip {
curl -s 'http://ipv4.wtfismyip.com/json' \
|jq -r '.YourFuckingIPAddress'
}
test -e ~/.banner && cat ~/.banner
# vi goodness is good
set -o vi
export EDITOR=`which vi`
# mac specific stuff
if [ $machine == "Mac" ]; then
alias brewup='brew update; brew upgrade; brew prune; brew cleanup; brew doctor'
export PATH="$HOME/.macbin:$PATH"
alias fixinkscape='wmctrl -r Inkscape -e 0,2560,1440,1280,800'
alias fixinkscapeExt='wmctrl -r Inkscape -e 0,0,0,1024,1024'
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
# added by Anaconda3 5.3.1 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/Users/jeremy/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/Users/jeremy/anaconda3/etc/profile.d/conda.sh" ]; then
. "/Users/jeremy/anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="/Users/jeremy/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda init <<<
export PATH="/opt/homebrew/opt/ruby/bin:$PATH"