-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc
More file actions
245 lines (209 loc) · 7.14 KB
/
Copy pathbashrc
File metadata and controls
245 lines (209 loc) · 7.14 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
234
235
236
237
238
239
240
241
242
243
244
245
# shellcheck disable=SC1090
export BASH_SILENCE_DEPRECATION_WARNING=1
# Ensure this is treated as an interactive shell for fzf and other tools
# This is especially important in devcontainer environments
case $- in
*i*) ;;
*) return;;
esac
add_path() {
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
PATH="$1:$PATH"
fi
}
echo_path() {
echo "path..."
tr : '\n' <<<"$PATH"
}
remove_path() {
PATH=$(tr : '\n' <<<"$PATH" | grep -v "^$1$" | paste -sd ':' -)
export PATH
}
clean_path() {
# shellcheck disable=SC1001
tr : '\n' <<<"$PATH" | awk '!x[$0]++' | grep \/ | grep -v game | paste -sd ":" -
}
reset_path() {
PATH=$(clean_path)
export PATH
}
# fuzzy cd: choose one directory with fzf and cd into it (bash)
unalias cdf 2>/dev/null # harmless if no alias
cdf() {
local sel
# produce a newline-separated list, ignore errors from find
# read only the first selected line (prevents multi-line selection problems)
IFS= read -r sel < <(find . -type d \( -name .git -o -name node_modules \) -prune -false -o -type d 2>/dev/null | fzf --height 40% --reverse --prompt='Dir> ') || return
[ -z "$sel" ] && return
cd "$sel" || printf 'cdf: failed to cd into %s\n' "$sel"
}
alias updatedb="sudo /usr/libexec/locate.updatedb"
remove_path "/usr/local/opt/perl/bin"
add_path "$HOME/.plenv/bin"
_load_plenv() {
if which plenv >/dev/null; then eval "$(plenv init -)"; fi
}
plenv() {
unset -f plenv perl
_load_plenv
plenv "$@"
}
perl() {
unset -f plenv perl
_load_plenv
perl "$@"
}
add_path "$HOME/.rvm/bin"
if command -v nvim >/dev/null 2>&1; then
export EDITOR=nvim
else
export EDITOR=vim
fi
add_path "$HOME/.vim/plugged/fzf/bin"
# fzf - fuzzy finder integration (requires interactive shell with TTY)
if [[ $- == *i* ]]; then
[ -f "$HOME"/.vim/plugged/fzf/shell/key-bindings.bash ] && . "$HOME"/.vim/plugged/fzf/shell/key-bindings.bash
[ -f "$HOME"/.vim/plugged/fzf/shell/completion.bash ] && . "$HOME"/.vim/plugged/fzf/shell/completion.bash
# Enable fzf completion for common commands and aliases
if type _fzf_setup_completion &>/dev/null; then
_fzf_setup_completion path nvim vim nv vi
fi
fi
[ -f "$HOME"/dot-files/local_bashrc ] && . "$HOME"/dot-files/local_bashrc
add_path "$HOME/local/bin"
# add_path "$HOME/local/bin/nvim-macos/bin" # Commented out - using package manager nvim instead
export NVM_DIR="$HOME/.nvm"
# Load nvm immediately (not lazy-loaded)
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
# The next line updates PATH for the Google Cloud SDK.
if [ -f 'Users/dallas/google-cloud-sdk/path.bash.inc' ]; then . '/Users/dallas/google-cloud-sdk/path.bash.inc'; fi
# The next line enables shell command completion for gcloud.
if [ -f '/Users/dallas/google-cloud-sdk/completion.bash.inc' ]; then . '/Users/dallas/google-cloud-sdk/completion.bash.inc'; fi
# Use Python 3 for Google Cloud SDK to avoid deprecation warnings
export CLOUDSDK_PYTHON=/usr/bin/python3
# Keep $HOME/.ssh/ssh_auth_sock pointed at a LIVE forwarded agent so tmux and
# reconnected sessions survive. VS Code/DevPod mint a new
# /tmp/auth-agent*/listener.sock on each reconnect, so the stable symlink goes
# stale and git fails with "Permission denied (publickey)". Self-heal here.
_mm_relink_ssh_agent() {
local stable="$HOME/.ssh/ssh_auth_sock" sock
if [ -n "$SSH_AUTH_SOCK" ] && [ "$SSH_AUTH_SOCK" != "$stable" ] \
&& [ -S "$SSH_AUTH_SOCK" ] \
&& SSH_AUTH_SOCK="$SSH_AUTH_SOCK" ssh-add -l >/dev/null 2>&1; then
ln -sf "$SSH_AUTH_SOCK" "$stable"
elif ! { [ -S "$stable" ] && SSH_AUTH_SOCK="$stable" ssh-add -l >/dev/null 2>&1; }; then
for sock in $(ls -1t /tmp/auth-agent*/listener.sock 2>/dev/null); do
if SSH_AUTH_SOCK="$sock" ssh-add -l >/dev/null 2>&1; then
ln -sf "$sock" "$stable"
break
fi
done
fi
export SSH_AUTH_SOCK="$stable"
}
_mm_relink_ssh_agent
set -o vi
unset PS1
whosonport() {
sudo lsof +c 0 -i :"$1"
}
rename_tab() {
if test "${TMUX_PANE+x}"; then
echo -en "\033Ptmux;\033\033]0;$1\a\033\\"
else
echo -en "\033]0;$1\a"
fi
}
# https://raim.codingfarm.de/blog/2013/01/30/tmux-update-environment/
tmux() {
#set -eux
local tmux=$(type -fp tmux)
if [ $# -ge 1 ] && [ -n "$1" ]; then
case "$1" in
update-environment | update-env | ue)
local v
while read v; do
if [[ $v == -* ]]; then
echo "unset $v"
unset ${v/#-/}
else
# Add quotes around the argument
v=${v/=/=\"}
v=${v/%/\"}
echo "export $v"
eval export "$v"
fi
done < <(tmux show-environment)
;;
# https://gist.github.com/marczych/10524654
ns)
tmux_session_name
tmux rename-session "$SESSION_NAME"
;;
*)
$tmux "$@"
;;
esac
else
tmux_session_name
$tmux new -s "$SESSION_NAME"
fi
}
alias cdf='cd "$(find . -type d | fzf)"'
# shellcheck disable=SC2046
unset OPENSSL_PREFIX
export PROMPT_COMMAND='_mm_relink_ssh_agent 2>/dev/null; _omp_hook 2>/dev/null; history -a'
export PATH
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"
# Created by `pipx` on 2025-09-22 13:12:03
export PATH="$PATH:/home/dhogan_maxmind_com/.local/bin"
export PATH=$PATH:$HOME/go/bin
export PATH="$HOME/.local/bin:$PATH"
# Auto-refresh tmux-tracked environment variables on new panes/windows
# This syncs SSH_AUTH_SOCK, GH_ENTERPRISE_TOKEN, LINEAR_TOKEN, etc.
# Only imports variables that are SET (not marked with - for removal)
if [ -n "$TMUX" ]; then
while IFS= read -r line; do
if [[ $line == *=* ]]; then
export "$line"
fi
done < <(tmux show-environment 2>/dev/null)
fi
# Helper to export a token and update tmux's session environment
# Usage: set_token GH_ENTERPRISE_TOKEN "your-token-value"
# or: set_token GH_ENTERPRISE_TOKEN (will prompt for value)
set_token() {
local name="$1"
local value="$2"
if [ -z "$value" ]; then
read -rsp "Enter value for $name: " value
echo
fi
export "$name=$value"
if [ -n "$TMUX" ]; then
tmux set-environment "$name" "$value"
fi
}
# Shortcuts for common tokens
alias set_ghe='set_token GH_ENTERPRISE_TOKEN'
alias set_linear='set_token LINEAR_TOKEN'
# Reclaim disk space (all regenerates). Biggest hog is stale test-fixture DBs;
# prune keeps anything used in the last 4h.
free-disk() {
echo "Free before: $(df -h --output=avail / | tail -1 | tr -d ' ')"
# Fixture DBs live on the shared cluster; run from any repo.
local repo
repo=$(git -C "$PWD" rev-parse --show-toplevel 2>/dev/null) || repo=/workspaces/mmwebsite
(cd "$repo" && go run ./go/pg/prune-test-databases 2>/dev/null)
go clean -cache -testcache -fuzzcache -modcache 2>/dev/null
command -v golangci-lint >/dev/null && golangci-lint cache clean 2>/dev/null
command -v pnpm >/dev/null && pnpm store prune >/dev/null 2>&1
# Sweep stale /tmp by age (safe: won't touch the current session's fresh files).
find /tmp -type f -atime +1 -delete 2>/dev/null
echo "Free after: $(df -h --output=avail / | tail -1 | tr -d ' ')"
df -h /
}
export PATH="/opt/nodejs/bin:$PATH"
eval "$(mise activate bash)"