-
Notifications
You must be signed in to change notification settings - Fork 0
/
bashrc
241 lines (205 loc) · 5.74 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
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
# Source global definitions
if [ -f /etc/bashrc ]; then
source /etc/bashrc
fi
if [ -f ~/.bashrc_arch ]; then
source ~/.bashrc_arch
fi
if [ -f ~/.bashrc_mac ]; then
source ~/.bashrc_mac
fi
if [ -f ~/.bashrc_hashicorp ]; then
source ~/.bashrc_hashicorp
fi
if [ -f ~/.bashrc_private ]; then
source ~/.bashrc_private
fi
export EDITOR="nvim"
export LANG=en_US.UTF-8
export LC_ALL=$LANG
export HISTCONTROL='ignoreboth:erasedups'
RESET='\e[0;0m'
RED='\e[0;31m'
GREEN='\e[0;32m'
YELLOW='\e[0;33m'
BLUE='\e[0;34m'
MAGENTA='\e[0;35m'
CYAN='\e[0;36m'
GIT_PROMPT_PREFIX="[${GREEN}±${RESET}"
GIT_PROMPT_CLEAN="${GREEN}✓${RESET}"
GIT_PROMPT_AHEAD="${CYAN}▴${RESET}"
GIT_PROMPT_BEHIND="${MAGENTA}▾${RESET}"
GIT_PROMPT_STAGED="${GREEN}●${RESET}"
GIT_PROMPT_UNSTAGED="${YELLOW}●${RESET}"
GIT_PROMPT_UNMERGED="${YELLOW}~${RESET}"
GIT_PROMPT_UNTRACKED="${RED}●${RESET}"
GIT_PROMPT_SUFFIX="${RESET}]"
git_branch() {
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
echo "${ref#refs/heads/}"
}
git_status() {
_INDEX=$(command git status --porcelain -b 2> /dev/null)
_STATUS=""
if $(echo "$_INDEX" | grep '^[AMRD]. ' &> /dev/null); then
_STATUS="$_STATUS$GIT_PROMPT_STAGED"
fi
if $(echo "$_INDEX" | grep '^.[MTD] ' &> /dev/null); then
_STATUS="$_STATUS$GIT_PROMPT_UNSTAGED"
fi
if $(echo "$_INDEX" | grep -E '^\?\? ' &> /dev/null); then
_STATUS="$_STATUS$GIT_PROMPT_UNTRACKED"
fi
if $(echo "$_INDEX" | grep '^UU ' &> /dev/null); then
_STATUS="$_STATUS$GIT_PROMPT_UNMERGED"
fi
if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then
_STATUS="$_STATUS$GIT_PROMPT_STASHED"
fi
if $(echo "$_INDEX" | grep '^## .*ahead' &> /dev/null); then
_STATUS="$_STATUS$GIT_PROMPT_AHEAD"
fi
if $(echo "$_INDEX" | grep '^## .*behind' &> /dev/null); then
_STATUS="$_STATUS$GIT_PROMPT_BEHIND"
fi
if $(echo "$_INDEX" | grep '^## .*diverged' &> /dev/null); then
_STATUS="$_STATUS$GIT_PROMPT_DIVERGED"
fi
if [[ -n $_STATUS ]]; then
printf $_STATUS
fi
}
git_prompt() {
local _branch=$(git_branch)
local _status=$(git_status)
local _result=""
if [[ "${_branch}x" != "x" ]]; then
_result="$GIT_PROMPT_PREFIX$_branch"
if [[ "${_status}x" != "x" ]]; then
_result="$_result $_status"
fi
_result="$_result$GIT_PROMPT_SUFFIX"
fi
if [[ -n $_result ]]; then
printf "$_result "
fi
}
date_prompt() {
printf "$MAGENTA$(date '+%Y-%m-%d %H:%M:%S')$RESET "
}
exit_status_prompt() {
last_status=$?
if [[ $last_status > 0 ]]; then
printf "${RED}$last_status${RESET} "
fi
}
# My Prompt
PS1="\[$BLUE\]\u\[$RESET\]@\h \[$BLUE\]\w \n\[$GREEN\]\$ \[$RESET\]"
PROMPT_COMMAND="exit_status_prompt; date_prompt; git_prompt;"
# Go Lang
export GOPATH="$HOME/code/go"
# User specific aliases and functions
alias t='tmux attach'
# Fix gpg-agent
export GPG_TTY=`tty`
# For building erlang
export KERL_CONFIGURE_OPTIONS="--disable-debug --without-javac"
export ERL_AFLAGS="-kernel shell_history enabled"
export RG_IGNORE='\
--glob "!**/*.egg-info/*" \
--glob "!**/*.pyc" \
--glob "!**/.build/*" \
--glob "!**/.direnv/*" \
--glob "!**/.hypothesis/*" \
--glob "!**/.mypy_cache/*" \
--glob "!**/.pytest_cache/*" \
--glob "!**/.serverless/*" \
--glob "!**/.shadow-cljs/*" \
--glob "!**/.webpack/*" \
--glob "!**/_build/*" \
--glob "!**/_nerves-tmp/*" \
--glob "!**/compiled/*" \
--glob "!**/deps/*" \
--glob "!**/elm-stuff/*" \
--glob "!**/node_modules/*" \
--glob "!.direnv/*" \
--glob "!.elixir_ls/*" \
--glob "!.git/*" \
--glob "!.pytest_cache/*" \
--glob "!.serverless/*" \
--glob "!.stack-work/*" \
--glob "!_build/*" \
--glob "!deps/*" \
--glob "!dist/*" \
--glob "!elm-stuff/*" \
--glob "!flow-typed/*" \
--glob "!htmlcov/*" \
--glob "!node_modules/*" \
--glob "!serverless/lib/*" \
--glob "!tags" \
--glob "!target/*" \
--glob "!tmp/*" \
'
export FZF_DEFAULT_COMMAND="rg --files --no-ignore --hidden --follow $RG_IGNORE"
# Add ssh keys
if [ -n "$(ps ax | rg ssh-agent | rg -v rg)" ]; then
keys=(
id_rsa
id_ed25519
)
for key in ${keys[@]}; do
keyfile="$HOME/.ssh/$key"
pub_key=$(cat $HOME/.ssh/$key.pub | awk '{print $2}')
if [[ -f $keyfile && -z "$(ssh-add -L | grep $pub_key)" ]]; then
ssh-add $keyfile
fi
done
fi
# fasd
if [ -n "$(which fasd)" ]; then
eval "$(fasd --init auto)"
alias v='f -e nvim'
fi
# direnv
if [ -n "$(which direnv)" ]; then
eval "$(direnv hook bash)"
fi
# This is in reverse order.
paths=(
/usr/local/opt/sqlite/bin
$HOME/.poetry/bin
/usr/local/sbin
$HOME/Library/Haskell/bin
/usr/local/go/bin
$GOPATH/bin
/usr/local/opt/openssl/bin
/Library/TeX/texbin
$HOME/.local/bin # $haskell_local_bin
$HOME/bin
)
for p in ${paths[@]}; do
if [[ -d $p ]]; then
export PATH="$p:$PATH";
fi
done
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
# Output my dotfiles status
printf "dotfiles status: $(cd $HOME/.dotfiles/ && git_prompt)\n"
# asdf start - - - - - - - - - -
## arch setup
if [ -d /opt/asdf-vm ]; then
source /opt/asdf-vm/asdf.sh
fi
# asdf end - - - - - - - - - -
# The next line updates PATH for the Google Cloud SDK.
if [ -f "$HOME/google-cloud-sdk/path.bash.inc" ]; then source "$HOME/google-cloud-sdk/path.bash.inc"; fi
# The next line enables shell command completion for gcloud.
if [ -f "$HOME/google-cloud-sdk/completion.bash.inc" ]; then source "$HOME/google-cloud-sdk/completion.bash.inc"; fi
cargo_env=$HOME/.cargo/env
if [ -f "$cargo_env" ]; then source "$cargo_env"; fi
if [ -f $HOME/.gitlabrc ]; then source $HOME/.gitlabrc; fi
# Postgres
export PG_LOCAL=postgres://postgres:postgres@localhost