-
Notifications
You must be signed in to change notification settings - Fork 0
/
_bashrc
461 lines (406 loc) · 12.5 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
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
# -*- shell-script -*-
# .bashrc
# run only for interactive non-login shells
# commands here for all shells
# try to work around Ubuntu 12.04 XAUTHORITY settings
# are we on the console *and* running lightdm *and* root?
# get a minimum PATH so we have something to work with
oPATH="$PATH"
PATH=/bin:/usr/bin:/usr/local/bin
export PATH
# this fixes some badness in X access when using sudo
if [ `id -u` -eq 0 ]; then
if [ "$XAUTHORITY" == "$HOME/.Xauthority" ]; then
if [ "$DISPLAY" == ":0" ]; then
x_cmd=`ps guaxww | grep /usr/bin/X | grep -v grep`
case "$x_cmd" in
*lightdm*)
XAUTHORITY=`echo $x_cmd | sed -e 's/^.*-auth //' | awk '{print $1}'`
export XAUTHORITY
;;
esac
fi
fi
fi
# figure out my current hostname
hostcmd=`type -path hostname || type -path uname || type -path uuname`
case $hostcmd in
*/uname*)
HOST=`$hostcmd` -n
;;
*/hostname*)
HOST=`$hostcmd`
;;
*/uuname*)
HOST=`$hostcmd -l`
;;
*)
HOST="unknown"
;;
esac
# what kind of machine am I on?
if [ -f ~/.mach_type ]; then
source ~/.mach_type
else
# some reasonable defaults
MACH_TYPE=unknown
X11=/usr/bin/X11
LOCALBIN=/usr/local/bin
fi
# set up path stuff
if [ -d ~/bin/$MACH_TYPE ]; then
MY_BIN=$HOME/bin/scripts:$HOME/bin/$MACH_TYPE
else
MY_BIN=$HOME/bin/scripts
fi
# extra bin dirs
EBIN=
if [ -e /usr/local/linkedin/bin ]; then
EBIN=$EBIN:.:/usr/local/linkedin/bin
fi
if [ -e /export/apps/xtools/bin ]; then
# xtools was a linkedin thing... probably don't need it unless you
# are at linkedin.
EBIN=$EBIN:/export/apps/xtools/bin
fi
if [ -e $HOME/pebble-dev ]; then
PEBBLE_HOME=$HOME/pebble-dev/PebbleSDK-current
EBIN=$EBIN:$PEBBLE_HOME/bin
export PEBBLE_HOME
fi
if [ -e $HOME/android-sdk-* ]; then
EBIN=$EBIN:`echo $HOME/android-sdk-*/tools`
EBIN=$EBIN:`echo $HOME/android-sdk-*/platform-tools`
fi
if [ -e /usr/local/opt/android-sdk ]; then
export ANDROID_HOME=/usr/local/opt/android-sdk
fi
# set up the path
PATH=$PREPATH:$MY_BIN:$LOCALBIN:$X11:/usr/ucb:/usr/bin:/bin:/usr/5bin
PATH=$PATH:/usr/etc:/etc:/usr/hosts:/usr/new:/usr/old:$EBIN:/usr/games
# mips and sun have separate bin directories for SysV-ish tools vs. BSD-ish
case $MACH_TYPE in
mips)
bsd_path=$PATH
att_path=$MY_BIN:/bin:/usr/bin:$PATH
;;
sun*)
bsd_path=$PATH
att_path=$MY_BIN:/usr/5bin:$PATH
;;
*)
bsd_path=$PATH
att_path=$PATH
;;
esac
# don't allow group writes, use this if you don't have your own
# private group (pretty much all Linux dists give you a private group
# now, so you probably don't need this... unless you're on a mac?).
if [ `id -un` != `id -gn` ]; then
umask 022
fi
# don't dump any cores (doesn't work on HP/UX?)
case $MACH_TYPE in
hp)
;;
*)
ulimit -c 0
;;
esac
# miscellaneous env vars:
EDITOR=`type -path jove || type -path vi`
MORE=-c
LESS=qedm
PAGER=`type -path less || type -path more`
# special hacks for LESS
case $MACH_TYPE in
linux|macosx)
LESS="${LESS}X"
;;
esac
case $PAGER in
*less)
less_version=`$PAGER -V 2>&1 | sed -e 1q | awk '{print $2}'`
;;
*)
less_version=unknown
;;
esac
# some older versions of less did things a little differently, unlikely
# to need this stuff any more
case $less_version in
332)
LESS="${LESS}w"
;;
340)
LESS="${LESS}~"
;;
*)
LESS="${LESS}wR"
;;
esac
# nethack >> rogue
NETHACKOPTIONS="DECgraphics,noconfirm,male,fixinv,nohelp,news,nonull"
NETHACKOPTIONS="${NETHACKOPTIONS},nopickup,norest_on_space,silent"
NETHACKOPTIONS="${NETHACKOPTIONS},sortpack,standout,time,noverbose"
NETHACKOPTIONS="${NETHACKOPTIONS},dogname:Spike,catname:Puff,fruit:mango"
# this is used by tip, or it was, when tip was a thing
REMOTE=~/.remote
XSHELL=`type -path bash`
# when using a mips workstation, this was important. probably not so
# much any more.
KEYMAP=mips
PGPPATH=$HOME/.pgp
IMM_IMAGE_DIR=$HOME/lib/images
DISPLAY_GAMMA=2.2
# fetch is a BSD thing.
FETCH_CMD="fetch -p"
# old palm pilot support for jpilot. don't really use this any more.
PILOTRATE=38400
PILOTPORT=/dev/pilot
# MM == mime encode/decode tools, used with NMH and exmh.
MM_CHARSET=iso-8859-1
#LANG=en_US
case "$LANG" in
*[Uu][Tt][Ff]*)
;;
*)
# not sure if this is still needed, causes some issues on systems
# where the default encoding is utf-8
LESSCHARSET=latin1
export LESSCHARSET
;;
esac
# more linkedin stuff
if [ -e /usr/local/linkedin/man ]; then
MANPATH="$MANPATH:/usr/local/linkedin/man"
fi
# export all the vars!
export EDITOR MORE LESS MANPATH NETHACKOPTIONS NNTPSERVER PAGER PRINTER
export REMOTE XSHELL KEYMAP PGPPATH IMM_IMAGE_DIR DISPLAY_GAMMA FETCH_CMD
export PILOTRATE PILOTPORT MM_CHARSET LANG
# do we have keybase? (can't use qtype here because we haven't loaded
# our .bash_funs yet... and we don't want to load them until after we
# have set up MEMORY_FILE)
if type keybase >/dev/null 2>&1; then
if keybase status 2>&1 | grep -sq "connect: no such file or directory"; then
echo -n "waiting up to 30 seconds for keybase"
ct=0
while [ $ct -lt 30 ]; do
if keybase status 2>&1 |
grep -sq "connect: no such file or directory"; then
:
else
break
fi
ct=`expr $ct + 1`
sleep 1
echo -ne "\rwaiting up to 30 seconds for keybase $ct"
done
fi
KB_USER=`keybase status | grep ^Username | awk '{print $NF}'`
fi
# got a Dropbox or keybase mounted? use that for persistent memory
# storage. otherwise use a local file.
for db in "/Volumes/Keybase ($USER)/private/$KB_USER" \
"/run/user/`id -u`/keybase/kbfs/private/$KB_USER" \
"/keybase/private/$KB_USER" \
"Dropbox (Personal)" \
"Dropbox"; do
case "$db" in
/*) ;;
*) db="$HOME/$db" ;;
esac
if [ -e "$db/memory.txt" ]; then
MEMORY_FILE="$db/memory.txt"
break
fi
done
if [ ! -e "$MEMORY_FILE" ]; then
MEMORY_FILE="$HOME/.memory"
fi
# load shell functions
if [ -f ~/.bash_funs ]; then source ~/.bash_funs; fi
# and aliases
if [ -f ~/.bash_aliases ]; then source ~/.bash_aliases; fi
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# this doesn't appear to be working the way I want it to, need to
# play with it some more. the intention is to automatically update
# the history behind the scenes whenever a command prompt is shown,
# no matter which shell it is in.
trap 'history -r' USR1
# do I have a prompt already? then I'm probably an interactive shell.
if [ "$PS1" -a ! "$RUNNING_CSSHX" ]; then
# interactive shell
interactive=true
# stick some git branch and status info in the prompt if in a git
# working directory. this magic comes courtesy of Shawn O. Pearce.
# https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
if [ -e ~/lib/sh/git-prompt.sh ]; then
. ~/lib/sh/git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=t
GIT_PS1_SHOWSTASHSTATE=t
GIT_PS1_SHOWUNTRACKEDFILES=t
GIT_PS1_SHOWUPSTREAM="auto"
GIT_PS1_SHOWCOLORHINTS=t
fi
# prompt string looks like "user@host:working/directory history bash$ "
# but it is really managed by the prompt_update command, see .bash_funs
PS1="\u@\h:\w \! bash\\\$ "
PROMPT_DIRTRIM=2
PROMPT_COMMAND='prompt_update'
# I used to play a game of Traveller via e-mail. Had a different MH
# config for use when playing and this was to help me know if my current
# shell was in PBEM mode or not. http://www.shoestring-graphics.com/traveller/
# has historical info about the game and a log of the mail associated with
# the game. I haven't looked at this stuff in a looooooong time.
if test -n "$PBEMMODE"; then
PS1="PBEM: $PS1"
fi
# interactive-only variables
shopt -s checkhash
# shopt -s checkjobs # I don't remember why I don't use this any more
shopt -s checkwinsize
shopt -s cmdhist
HISTCONTROL=ignorespace:ignoredups:erasedups
HISTTIMEFORMAT="%F %T "
HISTFILESIZE=5000
HISTSIZE=5000
MAILCHECK=60
auto_resume=
no_exit_on_failed_exec=
notify=
if test -t; then
# we are talking to a tty
# stty dec some unixes don't have this?!
stty erase '^?' intr '^C' kill '^U' eof '^D' susp '^Z'
if stty -a | grep -sq werase; then
stty werase '^W'
fi
# stiffle "talk" requests... but no one uses that any more, anyway.
qtype mesg && mesg n
fi
# terminal management for use with UW. UW was the "windowing"
# system on the AT&T 7300. I had one of these at home for a
# few years to use as a terminal. This is where the "s4"
# terminal type came from. The 7300 was also known as the 3b1.
# http://toastytech.com/guis/unixpc.html. Also see http://www.unixpc.org/.
if [ $TERM = s4 ]; then export UW_TERM="s4"; fi
if [ $TERM = vt100 ]; then export UW_TERM="vt100"; fi
if [ $TERM = ansi ]; then export UW_TERM="ansi"; fi
if [ $TERM = adm31 ]; then
if test -n "$UW_TERM" ; then
export TERM=$UW_TERM
export TERMCAP=$HOME/.termcap
# stty 2400 >/dev/tty
fi
fi
# UW took advantage of shell layers, too. I also used shell layers
# on the 3b2.
if [ x$LAYER != x ]; then
export TERMINFO=$HOME/.terminfo
fi
# this was for systems that didn't have the terminal size in the tty structure.
# the resize command output commands to set the ROWS and COLUMNS environment
# variables.
#if [ x$WINDOWID != x ]; then
# eval `resize`
#fi
fi
# homebrew is for additional software on MacOS X. http://brew.sh
#export HOMEBREW_GITHUB_API_TOKEN=SECRET:12d1bec63b6258041b213adffe8d797d91668e52:SECRET
# some python stuff here... pyenv is a slick mechanism for having different
# python builds installed that you can use with different projects.
export PYENV_ROOT=$HOME/.pyenv
mkdir -p "$PYENV_ROOT"
qtype pyenv && eval "$(pyenv init -)"
qtype pyenv-virtualenv-init && eval "$(pyenv virtualenv-init -)"
# pyenv completion from
# https://github.com/pyenv/pyenv/blob/master/completions/pyenv.bash
_pyenv() {
COMPREPLY=()
local word="${COMP_WORDS[COMP_CWORD]}"
if [ "$COMP_CWORD" -eq 1 ]; then
COMPREPLY=( $(compgen -W "$(pyenv commands)" -- "$word") )
else
local words=("${COMP_WORDS[@]}")
unset words[0]
unset words[$COMP_CWORD]
local completions=$(pyenv completions "${words[@]}")
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
fi
}
complete -F _pyenv pyenv
# more pyenv stuff for verisys
if [ "$VERISYS_CONFIG" ]; then
PATH=/usr/local/share/python:$PATH
export WORKON_HOME=$HOME/.virtualenvs
if [[ -x /usr/local/bin/python2.7 ]]; then
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2.7
elif [[ -x /usr/bin/python2.7 ]]; then
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python2.7
elif qtype python2.7; then
export VIRTUALENVWRAPPER_PYTHON=`which -p python2.7`
fi
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'
# we handle the prompt in our prompt_update function
export VIRTUAL_ENV_DISABLE_PROMPT=t
export PIP_VIRTUALENV_BASE=$WORKON_HOME
export PIP_RESPECT_VIRTUALENV=true
if [[ -r /usr/local/bin/virtualenvwrapper.sh ]]; then
. /usr/local/bin/virtualenvwrapper.sh
elif [[ -r /usr/bin/virtualenvwrapper.sh ]]; then
. /usr/bin/virtualenvwrapper.sh
elif qtype virtualenvwrapper.sh; then
. `which -p virtualenvwrapper.sh`
fi
fi
# bash completion
for base in "" "/usr/local" "/opt/homebrew"; do
if [ -e ${base}/etc/bash_completion ]; then
. ${base}/etc/bash_completion
fi
if [ -e ${base}/etc/bash_completion.d ]; then
for f in ${base}/etc/bash_completion.d/*; do
# patch for bash completion, missing "have" command, this gets
# unset by /usr/share/bash-completion/bash_completion, then
# gets used when we source the completion files here
have () {
unset -v have
_have $1 && have=yes
}
. $f
done
fi
done
# Okta AWS authentication
if [[ -f "$HOME/.okta/bash_functions" ]]; then
. "$HOME/.okta/bash_functions"
fi
if [[ -d "$HOME/.okta/bin" && ":$PATH:" != *":$HOME/.okta/bin:"* ]]; then
PATH="$HOME/.okta/bin:$PATH"
fi
# Chartbeat
# pants wants a lot of open files
ulimit -n 17000
# direnv setup
if qtype direnv; then
eval "$(direnv hook bash)"
fi
# clean up the PATH (get rid of duplicates, missing dirs, and blank entries)
PATH=`perl -e '
$path = $ENV{PATH};
@path_elements = split(m/:/, $path);
foreach $element (@path_elements) {
next if $element eq "";
next unless -d $element;
push(@new_path, $element);
}
$newpath = join(":", @new_path);
print "$newpath\n"; '`
export PATH
# dump path to temp file for other apps to pick up
echo $PATH > ~/.mypath