-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_profile
411 lines (328 loc) · 12.7 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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
######### Source ###########################
#
# Load .bashrc if it exists
test -f ~/.bashrc && source ~/.bashrc
####### Load tmux #########################
if [ -x "$(command -v tmux)" ] && \
[ -n "$PS1" ] && \
[[ ! "$TERM" =~ screen ]] && \
[[ ! "$TERM" =~ tmux ]] && \
[ -z "$TMUX" ]; then
exec tmux
fi
######### Load system specific stuff #######
OS="$(uname -s)"
if test "$OS" = "Darwin"; then
if [ ! -f $HOME/.mac_setup_complete ]; then
source $HOME/.mac_setup
fi
######### Architecture Flags ###############
# TODO: Update this when using M2 Mac
#export ARCHFLAGS="-arch x86_64"
######## For Homebrew ######################
arch=$(uname -m)
# If APPLE is unset or empty, default to 0 (false)
APPLE=1
if [[ $APPLE -eq 1 && $arch == "x86_64" ]]; then
BREW_PREFIX="/opt/brew"
elif [[ $arch == "arm64" ]]; then
BREW_PREFIX="/opt/homebrew"
else
BREW_PREFIX="/usr/local"
fi
export PATH="$BREW_PREFIX/bin:$BREW_PREFIX/sbin:$PATH"
if [[ $APPLE -eq 1 ]]; then
source "$BREW_PREFIX/etc/bash_completion.d/rubix"
fi
############## ALIASES:######################
alias top='top -s3 -o cpu -R -F'
alias project=". project"
alias localip="ipconfig getifaddr en0"
alias pi='ssh [email protected]' # Use a mosh server next time.
# TODO: Refactor to use minikube or whatever that isn't Docker.
export DOCKER_HOST=unix:///var/run/docker.sock
# This is so that docker instance can reach localhost postgresql. Not sure why I addeed thing above.
export DOCKERHOST="$(ifconfig en0 inet | grep "inet " | awk -F'[: ]+' '{ print $2 }')"
function dockbash() { docker exec -it $@ bash; }
function dockbashroot() { docker exec -u root -it $@ bash; }
####### Generic Colorizer ##################
# For diff, etc.
# TODO: Fix this. I'm not sourcing the right thing.
#source "`brew --prefix`/etc/grc.bashrc"
elif test "$OS" = "Linux"; then
:
##### Linux specfic Aliases ##################
# nothing here for now.
fi
##### Non-system specfic Aliases #################
alias badge="tput bel"
alias hidden='ls -d .*'
alias ls='ls -FA'
alias exit='jobs; exit'
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
alias l="ls"
alias sl="ls"
alias cd..='cd ..'
alias vim='nvim'
alias tf='terraform'
alias tfshortplan='tf plan -no-color | grep "replaced\|destroyed\|created\|forces\|updated" |grep -v "created_at"'
alias k='kubectl'
alias diff='diff --color'
###### Always use color output for `ls` #########
if ls --color > /dev/null 2>&1; then # GNU `ls`
colorflag="--color"
else # OS X `ls`
colorflag="-G"
fi
alias ls="command ls ${colorflag}"
export LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:'
############ PYTHON STUFF ##################
export CONDA_DEFAULT_ENV="py310"
######## Fancy Terminal Colors ##############
MAGENTA="\[\033[0;35m\]"
LIGHT_MAGENTA="\[\033[1;35m\]"
YELLOW="\[\033[1;33m\]"
BLUE="\[\033[0;34m\]"
LIGHT_BLUE="\[\033[1;34m\]"
LIGHT_GRAY="\[\033[0;37m\]"
WHITE="\[\033[1;37m\]"
CYAN="\[\033[0;36m\]"
LIGHT_CYAN="\[\033[1;36m\]"
GREEN="\[\033[0;32m\]"
BROWN="\[\033[0;33m\]"
RED="\[\033[0;31m\]"
LIGHT_RED="\[\033[1;31m\]"
DARK_GRAY="\[\033[1;30m\]"
LIGHT_GREEN="\[\033[1;32m\]"
ORANGE="\[\033[1;40m\]"
###### Shell colors #########################
export LS_OPTIONS='--color=auto'
export CLICOLOR='Yes'
export LSCOLORS=gxfxbEaEBxxEhEhBaDaCaD
###### Environmental variables #############
export EDITOR=vim
####### History stuff #######################
# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
# The following is from:
# http://askubuntu.com/questions/312444/how-to-make-the-command-line-history-apply-across-all-terminals
# Keeps history synced between all open terminals
HISTSIZE=10000
HISTFILESIZE=$HISTSIZE
HISTTIMEFORMAT="%d/%m/%y %T "
history() {
_bash_history_sync
builtin history "$@"
}
_bash_history_sync() {
builtin history -a
HISTFILESIZE=$HISTSIZE
builtin history -c
builtin history -r
}
######### For comprehensive shell logs #########
# Create history logging folder if does not exist
mkdir -p $HOME/.logs
history_log() {
local exit_status=$1
if [ "$(id -u)" -ne 0 ]; then
local datetime=$(date -u +"%Y-%m-%dT%H:%M:%S%z")
local hostname=$(hostname)
local directory=$(pwd)
local last_command=$(fc -ln -1 | sed 's/^[[:space:]]*//')
echo "${datetime} ${hostname} ${directory} exit:${exit_status} ${last_command}" >> ~/.logs/bash-history-$(date "+%Y-%m-%d").log
fi
}
function logs() { grep -h "$@" ~/.logs/*.log; }
# Write a copy of time-stamped history to a daily log file.
PROMPT_COMMAND='history_log $?'
# Might want to try this as well:
# http://www.pointsoftware.ch/howto-bash-audit-command-logger/
# https://debian-administration.org/article/543/Bash_eternal_history
######## For AWS ##########################
function whichaws {
caller=$(aws sts get-caller-identity)
alias=$(aws iam list-account-aliases --query AccountAliases[0] --output text)
region=$(aws configure get region)
account=$(echo $caller | jq -r '.Account')
echo "Account: $account"
echo "Alias: $alias"
UserId=$(echo $caller | jq -r '.UserId')
echo "UserId: $UserId"
UserARN=$(echo $caller | jq -r '.Arn')
echo "UserArn: $UserARN"
echo "Region: $region"
}
# I don't use this because it's too slow to run every prompt.
function aws_prompt {
if [ -n "$AWS_ACCESS_KEY_ID" ] && [ -x "$(command -v aws)" ]; then
if [ -z "$LAST_AWS_ACCESS_KEY_ID" ] || \
[ "$LAST_AWS_SECRET_ACCESS_KEY" != "$AWS_SECRET_ACCESS_KEY" ] || \
[ "$LAST_AWS_ACCESS_KEY_ID" != "$AWS_ACCESS_KEY_ID" ]; then
export LAST_AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID"
export LAST_AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY"
current=$(aws iam list-account-aliases --query AccountAliases[0] --output text)
if [ "$current" == "None" ]; then
current=$(aws sts get-caller-identity | jq -r '.Account')
fi
export CURRENT_AWS_ACCOUNT_ALIAS=$current
fi
echo -en "\033[0;35m<$CURRENT_AWS_ACCOUNT_ALIAS>"
fi
}
function update_kubeconfigs {
clusters=$(aws eks list-clusters | jq -r .clusters[])
for cluster in $clusters; do
aws eks update-kubeconfig --region us-west-2 --name $cluster
done
}
function aws_profile() {
# List all available AWS profiles
echo "Available AWS profiles:"
profiles=$(grep '\[profile ' ~/.aws/config | tr -d '[]' | awk '{print $2}')
select profile in $profiles; do
if [ -n "$profile" ]; then
# Export the AWS profile to the current shell
export AWS_PROFILE=$profile
echo "AWS profile set to: $AWS_PROFILE"
# Check if AWS_PROFILE already exists in .bash_profile
if grep -q '^export AWS_PROFILE=$' ~/.bash_profile ; then
# If it exists, update the existing AWS_PROFILE
sed -i.bak "s/^export AWS_PROFILE=.*$/export AWS_PROFILE=$profile/" ~/.bash_profile
else
# If it does not exist, add a new AWS_PROFILE
echo "export AWS_PROFILE=$profile" >> ~/.bash_profile
fi
echo "AWS profile updated in .bash_profile"
break
else
echo "Invalid option"
fi
done
}
#function get_token {
#credetials=$(aws sts assume-role --role-arn=$TF_VAR_config_role_arn --role-session=cli)
#AccessKeyId=$(echo $caller | jq -r '.Credentials.AccessKeyId')
#SecretAccessKey=$(echo $caller | jq -r '.Credentials.SecretAccessKey')
#SessionToken=$(echo $caller | jq -r '.Credentials.SessionToken')
#echo "export AWS_SECRET_ACCESS_KEY=
#echo "export AWS_ACCESS_KEY_ID=
#echo "export AWS_SESSION_TOKEN=
#}
# export "PROMPT_COMMAND=$PROMPT_COMMAND;aws_prompt"
######### Added for k8s ###################
function prompt_k8s {
k8s_current_context=$(kubectl config current-context 2> /dev/null)
if [[ $? -eq 0 ]] ; then echo -e "'$BLUE'("$k8s_current_context")"; fi
}
######### Added for Git ####################
function git-branch-name {
echo $(git rev-parse --abbrev-ref HEAD 2>/dev/null)
}
function git-unpushed {
if [ -d .git ]; then
brinfo=$(git branch -v | grep -F -f <(git-branch-name))
if [[ $brinfo =~ ("[ahead "([[:digit:]]*)]) ]]
then
echo "(${BASH_REMATCH[2]})"
fi
fi
}
PS1=''
#PS1+='$(prompt_k8s)'
if [[ $- == *i* ]]; then
source ~/.git-prompt.sh
source ~/.git-completion.bash
GIT_PS1_SHOWDIRTYSTATE=true
PS1=$PS1'$(
if [[ $(__git_ps1) =~ \*\)$ ]]
# a file has been modified but not added
then echo "'$RED'"$(__git_ps1 "<%s:$(git-unpushed)>")
elif [[ $(__git_ps1) =~ \+\)$ ]]
# a file has been added, but not commited
then echo "'$BROWN'"$(__git_ps1 "<%s:$(git-unpushed)>")
# the state is clean, changes are commited
else echo "'$GREEN'"$(__git_ps1 "<%s:$(git-unpushed)>")
fi)'$LIGHT_GRAY"\w "
export PS1
fi
# fi)'$LIGHT_GRAY"\w\342\232\241 "
###### shopt stuff #########################
# append to the history file, don't overwrite it
shopt -s histappend
# Autocorrect typos in path names when using `cd`
shopt -s cdspell;
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
####### less config ##########################
# make less more friendly for non-text input files, see lesspipe(1)
# Enable syntax-highlighting in less.
# brew install source-highlight
# First, add these two lines to ~/.bashrc
export LESSOPEN="| $BREW_PREFIX/bin/src-hilite-lesspipe.sh %s"
export LESS=" -R "
alias less='less -m -g -i --underline-special --SILENT'
alias more='less'
###### Xterm title ###########################
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
###### THIS STUFF SHOULD BE LAST ############
# Switch your environment for AWS and Github
if [ -f "$HOME/.aws/source-me.sh" ]; then
. "$HOME/.aws/source-me.sh"
fi
[ -f "$HOME/.credentials" ] && source "$HOME/.credentials"
# Stuff in my bin folder is always first
export PATH="${HOME}/bin:${PATH}"
export KUBERNETES_PROVIDER='aws'
# added by Anaconda3 4.2.0 installer
#export PATH="$HOME/anaconda3/bin:$PATH"
mkdir -p $HOME/code
cd $HOME/code
# eval "$(direnv hook bash)"
# For gnu internet utilities. They are prepended with 'g' but this will fix that:
# If these are missing, install with 'brew install coreutils'
PATH="$BREW_PREFIX/opt/inetutils/libexec/gnubin:$PATH"
# Disabling for now because messes with my PROMPT_COMMAND and my shell logging
#if [ -f ~/.iterm2_shell_integration.bash ]; then
# source ~/.iterm2_shell_integration.bash
#fi
# For K8s
source <(kubectl completion bash | sed s/kubectl/k/g)
# Add ssh keys to path
PATH="$PATH:$HOME/.ssh"
export PATH="$BREW_PREFIX/sbin:$PATH"
export PATH="$BREW_PREFIX/opt/node@16/bin:$PATH"
# eval $(minikube docker-env)
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/jonathanmorris/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/Users/jonathanmorris/anaconda3/etc/profile.d/conda.sh" ]; then
. "/Users/jonathanmorris/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/Users/jonathanmorris/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
# For NVM
#export NVM_DIR="$HOME/.nvm"
#[ -s "/usr/local/opt/nvm/nvm.sh" ] && \. "/usr/local/opt/nvm/nvm.sh" # This loads nvm
#[ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/usr/local/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
export BASH_SILENCE_DEPRECATION_WARNING=1
export PATH="/opt/brew/opt/openjdk/bin:$PATH"
export JAVA_HOME="/opt/brew/Cellar/openjdk/20.0.1/libexec/openjdk.jdk/Contents/Home"
export PATH="/opt/brew/opt/curl/bin:$PATH"
eval "$(direnv hook bash)"