-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc
More file actions
233 lines (197 loc) · 7.87 KB
/
bashrc
File metadata and controls
233 lines (197 loc) · 7.87 KB
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
# PATH setup
export PATH="$HOME/.bin:$PATH"
export PATH="/opt/homebrew/bin:$PATH"
export PATH="/opt/nvim/bin:$PATH"
export PATH="/opt/homebrew/sbin:$PATH"
export PATH="/opt/homebrew/Cellar/babashka/1.3.184/bin:$PATH"
export PATH="$HOME/.local/bin:$PATH"
export PATH="$HOME/.deno/bin:$PATH"
export PATH="/usr/local/bin:$PATH"
export PATH="$HOME/bin:$PATH"
export PATH="$HOME/go/bin:$PATH"
export PATH=$PATH:/usr/local/go/bin
export PATH="/Applications/j903/bin:$PATH"
export PATH="$HOME/.bun/bin:$PATH"
export PATH="/Users/josh/Library/pnpm:$PATH"
# Environment variables
export EDITOR=nvim
export LESS='-iMSx4 -RSFX -e'
export J_BIN_FOLDER="/Applications/j903/bin"
export J_INSTALLATION_FOLDER="/Applications/j903/"
export BUN_INSTALL="$HOME/.bun"
export PNPM_HOME="/Users/josh/Library/pnpm"
# Aliases
alias vim="nvim"
alias vi="nvim"
alias v="nvim"
alias g="git"
alias code="cd ~/code"
alias dotfiles="cd ~/dotfiles"
alias nbs="cd ~/code/whitecap/nbs-adapts"
alias sed="sed -E"
# Functions
kill_server() {
kill -9 $(lsof -i tcp:$1 -t -c^Google -c^firefox)
}
# Optional: Source external configs if they exist
[ -f "$HOME/.config/secrets" ] && source "$HOME/.config/secrets"
[ -f "$HOME/.cargo/env" ] && source "$HOME/.cargo/env"
[ -f "$HOME/.opam/opam-init/init.sh" ] && source "$HOME/.opam/opam-init/init.sh" 2>/dev/null || true
# direnv hook (if installed)
if command -v direnv &> /dev/null; then
eval "$(direnv hook bash)"
fi
# . "$HOME/.atuin/bin/env"
# # atuin (if installed)
# if command -v atuin &> /dev/null; then
# eval "$(atuin init bash)"
# fi
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
[ -f "$HOME/.cargo/env" ] && . "$HOME/.cargo/env"
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# The next line updates PATH for the Google Cloud SDK.
if [ -f '/home/ec2-user/google-cloud-sdk/path.bash.inc' ]; then . '/home/ec2-user/google-cloud-sdk/path.bash.inc'; fi
# The next line enables shell command completion for gcloud.
if [ -f '/home/ec2-user/google-cloud-sdk/completion.bash.inc' ]; then . '/home/ec2-user/google-cloud-sdk/completion.bash.inc'; fi
# Prompt (mirrors fish_prompt.fish)
__bash_prompt() {
local last_status=$?
# Colors — wrapped in \001..\002 so readline counts them as zero-width
local reset=$'\001\e[0m\002'
local red=$'\001\e[31m\002'
local green=$'\001\e[32m\002'
local yellow=$'\001\e[33m\002'
local blue=$'\001\e[34m\002'
local cyan=$'\001\e[36m\002'
local gray=$'\001\e[90m\002'
local brgreen=$'\001\e[92m\002'
local brblue=$'\001\e[94m\002'
local magenta=$'\001\e[35m\002'
local teal=$'\001\e[38;2;142;173;175m\002'
# Exit code
local exit_code=""
if [[ $last_status -ne 0 ]]; then
exit_code="<${red}${last_status}${reset}> "
fi
# Background job count
local jobs_num=""
local njobs
njobs=$(jobs -p 2>/dev/null | wc -l | tr -d ' ')
if [[ $njobs -gt 0 ]]; then
jobs_num="[${gray}${njobs}${reset}] "
fi
# CWD (replace $HOME with ~)
local cwd="${PWD/#$HOME/\~}"
local cwd_str="${cyan}${cwd}${reset}"
# User prefix: SSH session or Docker machine
local user_prefix=""
if [[ -n "$SSH_CLIENT" ]]; then
user_prefix="${USER} "
fi
if [[ -n "$DOCKER_MACHINE_NAME" ]]; then
user_prefix="${blue}${DOCKER_MACHINE_NAME}${reset} "
fi
# Override user prefix from ~/.prompt_prefix if it exists
if [[ -f "$HOME/.prompt_prefix" ]]; then
user_prefix="$(tr -d '\n' < "$HOME/.prompt_prefix") "
fi
# Prompt suffix
local suffix=">"
if [[ "$USER" == "root" || "$USER" == "toor" ]]; then
suffix="#"
fi
# Git branch with status color
local git_branch=""
if git status &>/dev/null; then
local branch_color="$green"
local git_status
git_status=$(git status 2>/dev/null)
if echo "$git_status" | grep -q 'Changes not staged for commit:\|Untracked files:'; then
branch_color="$red"
elif echo "$git_status" | grep -q 'Changes to be committed:'; then
branch_color="$yellow"
fi
local cur_branch
cur_branch=$(git branch 2>/dev/null | grep '^\* ' | sed 's/^\* //')
if [[ "$cur_branch" == "(HEAD detached"* ]]; then
cur_branch="detached"
fi
if [[ -n "$cur_branch" ]]; then
if [[ ${#cur_branch} -gt 21 ]]; then
cur_branch="${cur_branch:0:18}..."
fi
if echo "$git_status" | grep -q 'Your branch is ahead of'; then
cur_branch="${cur_branch}↥"
elif echo "$git_status" | grep -q 'Your branch is behind'; then
cur_branch="${cur_branch}↧"
fi
git_branch=" on ${branch_color}${cur_branch}${reset}"
fi
fi
# Tool versions (shown when relevant project files are present)
local tool_versions=""
if { [[ -e ./go.mod ]] || [[ -e ./Gopkg.toml ]]; } && command -v go &>/dev/null; then
local ver
ver=$(go version 2>/dev/null | grep -oE 'go[0-9]+\.[0-9]+\.?[0-9]*')
[[ -n "$ver" ]] && tool_versions+=" with ${teal}${ver}${reset}"
fi
if [[ -e ./mix.exs ]] && command -v elixir &>/dev/null; then
local ver
ver=$(elixir -v 2>/dev/null | grep -oE 'Elixir [0-9]+\.[0-9]+\.?[0-9]*' | sed 's/Elixir //')
[[ -n "$ver" ]] && tool_versions+=" with ${magenta}ex${ver}${reset}"
fi
if [[ -e ./package.json ]] && command -v node &>/dev/null; then
local ver
ver=$(node -v 2>/dev/null | sed 's/^v//')
if [[ -n "$ver" ]]; then
tool_versions+=" with ${brgreen}node${ver}${reset}"
if [[ -e ./tsconfig.json ]] && command -v tsc &>/dev/null; then
local ts_ver
ts_ver=$(tsc -v 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.?[0-9]*')
[[ -n "$ts_ver" ]] && tool_versions+=" and ${cyan}ts${ts_ver}${reset}"
fi
fi
fi
if [[ -e ./pubspec.yaml ]] && command -v dart &>/dev/null; then
local ver
ver=$(dart --version 2>&1 | grep -oE '[0-9]+\.[0-9]+\.?[0-9]*' | head -1)
[[ -n "$ver" ]] && tool_versions+=" with ${brblue}dart${ver}${reset}"
fi
if [[ -e ./Dockerfile ]] && command -v docker &>/dev/null; then
local ver
ver=$(docker --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.?[0-9]*' | head -1)
[[ -n "$ver" ]] && tool_versions+=" on ${blue}docker${ver}${reset}"
fi
if [[ -n "$VIRTUAL_ENV" ]]; then
local venv_name
venv_name=$(basename "$VIRTUAL_ENV")
tool_versions+=" via ${yellow}(${venv_name})${reset}"
fi
# Assemble prompt (two lines when there's git/tool info, one line otherwise)
local top="${cwd_str}${git_branch}${tool_versions}"
local bottom="${user_prefix}${jobs_num}${exit_code}${suffix} "
if [[ -z "$git_branch" && -z "$tool_versions" ]]; then
PS1="${top} ${bottom}"
else
PS1="${top}\n${bottom}"
fi
}
PROMPT_COMMAND='__bash_prompt'
# >>> modal initialize >>>
export PATH=/usr/local/aws-cli/v2/current/bin:$PATH
# AWS authenticator for accessing EKS clusters
export PATH=$PATH:$HOME/.aws/bin:$HOME/.pulumi/bin
# Add the check_kube_context to your PROMPT
function check_kube_context() {
KUBE_CONTEXT=$(kubectl config current-context 2>/dev/null)
# If not empty string, assume any context that doesn't contain substring 'dev' is production
if [[ -n "$KUBE_CONTEXT" && ! "$KUBE_CONTEXT" =~ "dev" ]]; then
echo "%{$fg_bold[yellow]%}[CAUTION: K8S PROD CONTEXT]%{$reset_color%} "
fi
}
PROMPT='$(check_kube_context)'$PROMPT
export PATH=/home/ec2-user/bin:$PATH
[[ -e "/home/ec2-user/lib/oracle-cli/lib/python3.9/site-packages/oci_cli/bin/oci_autocomplete.sh" ]] && source "/home/ec2-user/lib/oracle-cli/lib/python3.9/site-packages/oci_cli/bin/oci_autocomplete.sh"
export PATH=$PATH:$HOME/lib/oracle-cli/bin