-
Notifications
You must be signed in to change notification settings - Fork 19
/
bashrc
292 lines (245 loc) · 6.69 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
#!/bin/bash
#
# Mitchell Hashimoto's bash environment
# Much taken from Ryan Tomayko (thanks!)
# Basics
: ${HOME=~}
: ${LOGNAME=$(id -un)}
: ${UNAME=$(uname)}
# Complete hostnames from this file
: ${HOSTFILE=~/.ssh/known_hosts}
#-------------------------------------------------------------------------------
# Shell Options
#-------------------------------------------------------------------------------
# System bashrc
test -r /etc/bash.bashrc && . /etc/bash.bashrc
# Notify bg task completion immediately
set -o notify
# Fucking mail notifications
unset MAILCHECK
# default umask
umask 0022
# Terminal type
case $UNAME in
CYGWIN* | MINGW32*)
export TERM=cygwin
;;
*)
export TERM=xterm-256color
;;
esac
#-------------------------------------------------------------------------------
# Path
#-------------------------------------------------------------------------------
case $UNAME in
MINGW*)
# Don't touch the default PATH, it inherits Windows.
;;
*)
# Various sbins
PATH="/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin"
PATH="/usr/local/bin:$PATH"
;;
esac
# OS-Specific path stuff
if [[ `uname` == "Darwin" ]]; then
alias emacs="/usr/local/Cellar/emacs/23.3/Emacs.app/Contents/MacOS/Emacs -nw"
elif [[ `uname` == "Linux" ]]; then
PATH="/usr/bin/perlbin/vendor:$PATH"
fi
# ~/bin if it exists
test -d "$HOME/bin" &&
PATH="$HOME/bin:$PATH"
# texbin if it exists for LaTeX stuff
test -d "/usr/texbin" &&
PATH="/usr/texbin:$PATH"
# Heroku toolbelt
test -d "/usr/local/heroku/bin" &&
PATH="/usr/local/heroku/bin:$PATH"
#-------------------------------------------------------------------------------
# Env. Configuration
#-------------------------------------------------------------------------------
# detect interactive shell
case "$-" in
*i*) INTERACTIVE=yes ;;
*) unset INTERACTIVE ;;
esac
# detect login shell
case "$0" in
-*) LOGIN=yes ;;
*) unset LOGIN ;;
esac
# Proper locale
: ${LANG:="en_US.UTF-8"}
: ${LANGUAGE:="en"}
: ${LC_CTYPE:="en_US.UTF-8"}
: ${LC_ALL:="en_US.UTF-8"}
export LANG LANGUAGE LC_CTYPE LC_ALL
# Always use passive mode FTP
: ${FTP_PASSIVE:=1}
export FTP_PASSIVE
# Ignore backups, CVS directories
FIGNORE="~:CVS:#:.pyc"
HISTCONTROL=ignoreboth
# XDG config. This is different on Mac for historical reasons, but
# on our Linux dev machines we can keep it clean. Its important anything
# we do that uses the XDG directories uses the exported env vars directly.
case $UNAME in
Linux*)
export XDG_CONFIG_HOME="$HOME/.config"
;;
*)
export XDG_CONFIG_HOME="$HOME"
;;
esac
# Silence deprecation on Catalina
export BASH_SILENCE_DEPRECATION_WARNING=1
#-------------------------------------------------------------------------------
# Editor and Pager
#-------------------------------------------------------------------------------
EDITOR="vim"
export EDITOR
PAGER="less -FirSwX"
MANPAGER="$PAGER"
export PAGER MANPAGER
#-------------------------------------------------------------------------------
# Prompt
#-------------------------------------------------------------------------------
RED="\[\033[0;31m\]"
BROWN="\[\033[0;33m\]"
GREY="\[\033[0;97m\]"
GREEN="\[\033[0;32m\]"
BLUE="\[\033[0;34m\]"
PS_CLEAR="\[\033[0m\]"
SCREEN_ESC="\[\033k\033\134\]"
COLOR1="${BLUE}"
COLOR2="${BLUE}"
P="\$"
prompt_simple() {
unset PROMPT_COMMAND
PS1="\W\$(parse_git_branch) → "
PS2="> "
}
prompt_compact() {
unset PROMPT_COMMAND
PS1="${COLOR1}${P}${PS_CLEAR} "
PS2="> "
}
prompt_color() {
local remote=""
if grep docker /proc/1/cgroup -qa >/dev/null 2>&1; then
remote="🐶 "
fi
PS1="${GREEN}${remote}\W\$(parse_git_branch) → ${GREY}"
PS2="\[[33;1m\]continue \[[0m[1m\]> "
}
parse_git_branch() {
[ -d .git ] || return 1
git symbolic-ref HEAD 2> /dev/null | sed 's#\(.*\)\/\([^\/]*\)$# \2#'
}
#-------------------------------------------------------------------------------
# Aliases / Functions
#-------------------------------------------------------------------------------
alias dul='du -h --max-depth=1'
alias hi='history | tail -20'
# Git aliases
alias ga='git add'
alias gc='git commit'
alias gco='git checkout'
alias gcp='git cherry-pick'
alias gdiff='git diff'
alias gl='git prettylog'
alias gp='git push'
alias gs='git status'
alias gt='git tag'
# Others
alias be='bundle exec'
alias v='vagrant'
# Usage: puniq [path]
# Remove duplicate entries from a PATH style value while
# retaining the original order.
puniq() {
echo "$1" |tr : '\n' |nl |sort -u -k 2,2 |sort -n |
cut -f 2- |tr '\n' : |sed -e 's/:$//' -e 's/^://'
}
#-------------------------------------------------------------------------------
# SSH Agent
#-------------------------------------------------------------------------------
SSH_ENV=$HOME/.ssh/environment
function start_ssh_agent {
if [ ! -x "$(command -v ssh-agent)" ]; then
return
fi
if [ ! -d "$(dirname $SSH_ENV)" ]; then
mkdir -p $(dirname $SSH_ENV)
chmod 0700 $(dirname $SSH_ENV)
fi
ssh-agent | sed 's/^echo/#echo/' > ${SSH_ENV}
chmod 0600 ${SSH_ENV}
. ${SSH_ENV} > /dev/null
ssh-add
}
# Source SSH agent settings if it is already running, otherwise start
# up the agent proprely.
if [ -f "${SSH_ENV}" ]; then
. ${SSH_ENV} > /dev/null
# ps ${SSH_AGENT_PID} doesn't work under cywgin
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
start_ssh_agent
}
else
case $UNAME in
MINGW*)
;;
*)
start_ssh_agent
;;
esac
fi
#-------------------------------------------------------------------------------
# Other
#-------------------------------------------------------------------------------
# Plugins
PLUGINS=(
# Must be run first to setup the environment
"linux"
"depot_tools"
"gcloud"
"git"
"go"
"gvm"
"java"
"latex"
"mdv"
"nvm"
"rbenv"
"rvm"
"scala"
"tmux"
"windows"
)
for plugin in "${PLUGINS[@]}"
do
plugin_path="$HOME/.bash.d/${plugin}"
test -f $plugin_path && source $plugin_path
done
#-------------------------------------------------------------------------------
# User Shell Environment
#-------------------------------------------------------------------------------
case $UNAME in
MINGW*)
# Don't condense path, since function doesn't work here.
;;
*)
# Condense path variables
PATH=$(puniq $PATH)
MANPATH=$(puniq $MANPATH)
;;
esac
# Set default prompt if interactive
test -n "$PS1" &&
prompt_color
# Setup TTY for GPG
export GPG_TTY=$(tty)
# added by travis gem
[ -f /Users/mitchellh/.travis/travis.sh ] && source /Users/mitchellh/.travis/travis.sh