-
Notifications
You must be signed in to change notification settings - Fork 0
/
.profile
225 lines (201 loc) · 5.97 KB
/
.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
# Environment
## Shell Options
export HISTCONTROL=ignoreboth
export HISTIGNORE='ls:bg:fg:history'
export HISTSIZE=100000
# shopt -s autocd # automatically cd if first arg is a directory
shopt -s cdspell # fix common spelling mistakes
shopt -s histappend # update history after each command
shopt -s nocaseglob # ignore case when matching
## Path
PATH=${PATH}:/usr/local/sbin
## Per-OS environment
export UNAME_SYSTEM=$(uname -s)
if [[ $UNAME_SYSTEM == 'Darwin' ]]; then
export BASH_SILENCE_DEPRECATION_WARNING=1
if [[ -d /opt/homebrew ]]; then
export BREW_PREFIX='/opt/homebrew'
else
export BREW_PREFIX='/usr/local'
fi
export EDITOR="${BREW_PREFIX}/bin/vi"
PATH=${BREW_PREFIX}/bin:$PATH
PATH=${BREW_PREFIX}/sbin:$PATH
else
export EDITOR='/usr/bin/vim'
fi
## Aliases
alias brewdump='brew bundle dump -v -f --describe'
alias c-='cd -'
alias cat='ccat'
alias cdd='cd ..'
alias cddd='cd ../..'
alias cdddd='cd ../../..'
alias cddddd='cd ../../../..'
alias cdddddd='cd ../../../../..'
alias d='docker'
alias dc='docker-compose'
alias did="vim +'normal Go' +'r!date' ~/did.txt"
alias dt="git --git-dir=${HOME}/.dotfiles --work-tree=${HOME}"
alias dtt="GIT_DIR=${HOME}/.dotfiles GIT_WORK_TREE=${HOME} tig"
alias ghpr="gh pr create"
alias hg='history | grep -i'
alias lh='ls -lh'
alias ll='ls -l'
alias ls='ls -G'
alias mc='mc --nocolor'
alias po='popd'
alias pu='pushd'
alias rp='echo "Reloading ~/.profile"; source ~/.profile'
alias ws='cd ~/Workspace/'
alias va='. .venv/bin/activate'
alias vd='deactivate'
if [[ $UNAME_SYSTEM == 'Darwin' ]]; then
alias cdi='cd "${HOME}/Library/Mobile Documents/com~apple~CloudDocs"'
alias pui='pushd "${HOME}/Library/Mobile Documents/com~apple~CloudDocs"'
alias tm='diskutil unmount /Volumes/*\ Mascheen'
alias ts='tmutil status'
alias tl='tmutil listbackups'
alias tll='tmutil latestbackup'
alias tstop='tmutil stopbackup'
fi
## Prompt
case "$TERM" in
screen* | xterm* | rxvt*)
# the $DIRSTACK substitution of "~" for $HOME does not work in bash 4
PROMPT_COMMAND='echo -ne "\033]0;${HOSTNAME}\007"; __git_ps1 "\n$([[ -n $VIRTUAL_ENV ]] && echo \>\>\> VENV:\(${VIRTUAL_ENV//$HOME/\~}\))\n${DIRSTACK[*]//$HOME/~}" "\n$(date "+[%Y-%m-%d %H:%M:%S]") \u@\h> " ":{%s}"; history -a'
;;
*) ;;
esac
PS1="\n\w\n\u@\h> "
## AWS
export AWS_PROFILE=default
## Go
export GOPATH=~/Workspace/go
export GOBIN=$GOPATH/bin
PATH=${PATH}:${GOBIN}
## Java
export JAVA_HOME=/usr/local/Cellar/openjdk\@17/17.0.8.1/
## MySQL
PATH=${PATH}:${BREW_PREFIX}/opt/[email protected]/bin
## NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# Command completion
## AWS CLI
aws_completion_dir=${BREW_PREFIX}/etc/bash_completion.d
. $aws_completion_dir/aws_bash_completer
## Docker
docker_completion_dir=${BREW_PREFIX}/etc/bash_completion.d
. $docker_completion_dir/docker
## Git
git_completion_dir=${BREW_PREFIX}/etc/bash_completion.d
. $git_completion_dir/git-completion.bash
. $git_completion_dir/git-prompt.sh
export GIT_PS1_SHOWCOLORHINTS=true
export GIT_PS1_SHOWUNTRACKEDFILES=true
export GIT_PS1_SHOWDIRTYSTATE=true
## Kubectl
kubectl_completion_dir=${BREW_PREFIX}/etc/bash_completion.d
[[ -f $kubectl_completion_dir/kubectl ]] && . $kubectl_completion_dir/kubectl
## M
m_completion_dir=${BREW_PREFIX}/etc/bash_completion.d
. $m_completion_dir/m
## Make
complete -W "\`grep -oE '^[a-zA-Z0-9_.-]+:([^=]|$)' ?akefile | sed 's/[^a-zA-Z0-9_.-]*$//'\`" make
## MAS
mas_completion_dir=${BREW_PREFIX}/etc/bash_completion.d
. $mas_completion_dir/mas
# Functions
## SSH agent forwarding socket environment workaround
function refresh_socket {
if [[ $UNAME_SYSTEM == 'Darwin' ]]; then
socket=$(find /private/tmp -user $USER -type s -name Listeners 2>/dev/null | xargs ls -1t | head -1)
else
socket=$(find /tmp -user $USER -type s -name agent.* 2>/dev/null | xargs ls -1t | head -1)
fi
if [ -S $socket ]; then
export SSH_AUTH_SOCK=$socket
fi
}
## AWS SSO login
function alogin {
if [ "$1" == "" ]; then
echo -e "Usage: alogin <profile>\n--------"
echo "$(aws configure list-profiles)"
return 1
fi
if ! aws sso login --profile "$1"; then
echo "Could not log in to AWS"; return 1
fi
export AWS_PROFILE="$1"
echo "Account ID: $(aws sts get-caller-identity | jq -r .Account)"
aws configure list
}
## AWS Context
function acontext {
echo "AWS session"
echo "----------"
if aws sts get-caller-identity; then
echo
echo "AWS profile"
echo "----------"
aws configure list
[ "$?" != "0" ] && echo "***********"
fi
echo
echo "Kubernetes context"
echo "----------"
kubectl config current-context
}
## Utility functions
function print() {
echo ">>> [$(time_now)] $1"
}
function print_debug() {
[ "$DEBUG" == "1" ] && echo "### [$(time_now)] $1"
}
function print_err() {
echo "*** [$(time_now)] $1"
}
function time_now() {
date '+%Y-%m-%d %H:%M:%S' | tr -d '\n'
}
## Set kubectl context
function set_kubectl_context() {
local current_context
local contexts
local pattern
pattern="$1"
function get_kubectl_context() {
kubectl config current-context | tr -d '\n'
}
current_context="$(get_kubectl_context)"
if [[ "$current_context" =~ $pattern ]]; then
print "kubectl current context now '$current_context'"
return
fi
print "The current kubectl context does not match '${pattern}'"
# kubectl config get-contexts does not support structured output so we need this mess
contexts="$(kubectl config get-contexts --no-headers | sed -E -e 's/^[ \*]+([a-z:0-9\/-]+)[ ].+$/\1/')"
for context in $contexts; do
if [[ "$context" =~ $pattern ]]; then
print "Changing active kubectl context"
kubectl config use-context "$context"
print "kubectl current context now '$(get_kubectl_context)'"
return
fi
done
print_err "Could not find a kubectl context matching '${pattern}'"
print_err "Available contexts are:"
echo "$contexts"
exit 1
}
#if [[ -v $SSH_AUTH_SOCK && -S $SSH_AUTH_SOCK ]]; then
# # SSH auth socket exists, NOP
# true
#else
# refresh_socket
#fi
# Added by OrbStack: command-line tools and integration
# source ~/.orbstack/shell/init.bash 2>/dev/null || :