-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbashrc
More file actions
executable file
·600 lines (512 loc) · 21.5 KB
/
bashrc
File metadata and controls
executable file
·600 lines (512 loc) · 21.5 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
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
# Source common definitions
__bashrc_main() {
local SH_SOURCE_FILE SH_SOURCE_DIR SH_SOURCE_FILE_ESCAPED
if [ -n "$ZSH_VERSION" ]; then
SH_SOURCE_FILE=${(%):-%x}
elif [[ -n "$BASH_VERSION" ]]; then
SH_SOURCE_FILE=${BASH_SOURCE[0]}
fi
while [[ -L "$SH_SOURCE_FILE" ]]; do
SH_SOURCE_FILE=$(readlink "$SH_SOURCE_FILE")
done
SH_SOURCE_DIR=$(dirname "$SH_SOURCE_FILE")
SH_SOURCE_DIR=$(
cd "$SH_SOURCE_DIR" >/dev/null
pwd
)
SH_SOURCE_FILE=$(basename "$SH_SOURCE_FILE")
SH_SOURCE_FILE_ESCAPED=${SH_SOURCE_FILE// /_}
# SH_SOURCE_DIR is a full path to the location of this script
eval "$(
cat <<EOF
__get_${SH_SOURCE_FILE_ESCAPED}_dir() {
echo $SH_SOURCE_DIR
}
__get_${SH_SOURCE_FILE_ESCAPED}_file() {
echo $SH_SOURCE_FILE
}
__get_sh_scripts_dir() {
echo "$SH_SOURCE_DIR"
}
__get_sh_scripts_file() {
echo "$SH_SOURCE_FILE"
}
EOF
)"
local SH_COLOR_DEFS
if [[ -e "$SH_SOURCE_DIR/configure_colors" ]]; then
SH_COLOR_DEFS=$(cat "$SH_SOURCE_DIR/configure_colors")
fi
local SH_OS_DEFS
if [[ -e "$SH_SOURCE_DIR/configure_os" ]]; then
SH_OS_DEFS=$(cat "$SH_SOURCE_DIR/configure_os")
fi
eval "$(
cat <<EOF
__sh_color_definitions() {
echo "$SH_COLOR_DEFS"
}
__sh_os_definitions() {
echo "$SH_OS_DEFS"
}
EOF
)"
eval "$(__sh_color_definitions)"
eval "$(__sh_os_definitions)"
local SH_INTERACTIVE
case $- in
*i*)
# interactive shell
SH_INTERACTIVE=1
;;
esac
# Windows OpenSSH doesn't pass SSH env vars into WSL; import them
if [[ $SH_OS_FLAVOR == WSL && -z $SSH_CONNECTION ]]; then
local _win_ssh
_win_ssh=$(cmd.exe /c "echo %SSH_CONNECTION%" 2>/dev/null | tr -d '\r\n')
if [[ -n "$_win_ssh" && "$_win_ssh" != "%SSH_CONNECTION%" ]]; then
export SSH_CONNECTION="$_win_ssh"
_win_ssh=$(cmd.exe /c "echo %SSH_CLIENT%" 2>/dev/null | tr -d '\r\n')
[[ -n "$_win_ssh" && "$_win_ssh" != "%SSH_CLIENT%" ]] && export SSH_CLIENT="$_win_ssh"
fi
unset _win_ssh
fi
# When SSHing into Windows OpenSSH with WSL as shell, start in home dir
if [[ $SH_OS_FLAVOR == WSL && -n $SSH_CONNECTION && $PWD == /mnt/[cC]/* ]]; then
cd ~
fi
. "${SH_SOURCE_DIR}/shrc_helpers"
# Ghostty terminfo fallback (must be before tmux auto-attach)
if [[ "$TERM" == "xterm-ghostty" ]]; then
if ! infocmp xterm-ghostty >/dev/null 2>&1; then
export TERM=xterm-256color
fi
fi
# Show MOTD on SSH login (Linux; inside tmux the pre-attach output is lost)
if [[ $SH_INTERACTIVE && -n $SSH_CONNECTION && $SH_OS_TYPE == Linux && -f /run/motd.dynamic && -z $MOTD_SHOWN ]]; then
export MOTD_SHOWN=1
cat /run/motd.dynamic
fi
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'Configuring environment for '$COLOR_GREEN_BOLD'Bash '$COLOR_YELLOW_BOLD${BASH_VERSINFO[0]}'.'${BASH_VERSINFO[1]}'.'${BASH_VERSINFO[2]}$COLOR_NONE' on '$COLOR_GREEN_BOLD$SH_OS_DISTRO$COLOR_NONE' '$COLOR_YELLOW_BOLD$SH_OS_RELEASE$COLOR_NONE' ('$COLOR_GREEN_BOLD$SH_OS_TYPE$COLOR_NONE')'
# Homebrew (early, before tmux auto-attach needs it on PATH)
if [[ $SH_OS_TYPE == OSX ]]; then
if [[ -f /opt/homebrew/bin/brew ]]; then
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'Configuring '$COLOR_GREEN_BOLD'Homebrew'$COLOR_NONE
export HOMEBREW_NO_ENV_HINTS=1
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
elif [[ $SH_OS_TYPE == Linux ]]; then
if [[ -f /home/linuxbrew/.linuxbrew/bin/brew ]]; then
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'Configuring '$COLOR_GREEN_BOLD'Linuxbrew'$COLOR_NONE
export HOMEBREW_NO_ENV_HINTS=1
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
fi
local BREW_DIR
BREW_DIR=$(brew --prefix 2>>/dev/null)
if [ -z "$BREW_DIR" ]; then
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e $COLOR_GREEN_BOLD'Homebrew'$COLOR_NONE' not installed'
else
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e $COLOR_GREEN_BOLD'Homebrew'$COLOR_NONE' installed at '$COLOR_YELLOW_BOLD$BREW_DIR$COLOR_NONE
fi
# SSH configuration (must run before tmux auto-attach so the agent
# environment is inherited by the tmux session)
if [[ $SH_OS_TYPE == Windows ]]; then
# Use Windows native OpenSSH so that ssh/scp/ssh-add talk to the
# Windows ssh-agent service instead of a standalone Git Bash agent.
# WIN_OPENSSH_DIR is set by shrc.cmd; fall back to the well-known path.
local _win_ssh_dir="${WIN_OPENSSH_DIR:-/c/Windows/System32/OpenSSH}"
_win_ssh_dir="${_win_ssh_dir//\\//}" # backslash → forward slash
[[ $_win_ssh_dir != /* ]] && _win_ssh_dir="/c${_win_ssh_dir#C:}" # C:\… → /c/…
if [[ -x "$_win_ssh_dir/ssh.exe" ]]; then
# Shell functions override PATH, so Git Bash's /usr/bin/ssh is bypassed.
# Use eval to bake the resolved path into the function bodies,
# since _win_ssh_dir is local and will be gone after this function exits.
eval "ssh() { \"$_win_ssh_dir/ssh.exe\" \"\$@\"; }"
eval "ssh-add() { \"$_win_ssh_dir/ssh-add.exe\" \"\$@\"; }"
eval "scp() { \"$_win_ssh_dir/scp.exe\" \"\$@\"; }"
eval "sftp() { \"$_win_ssh_dir/sftp.exe\" \"\$@\"; }"
export -f ssh ssh-add scp sftp
export GIT_SSH="$_win_ssh_dir/ssh.exe"
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'Using Windows native '$COLOR_GREEN_BOLD'OpenSSH'$COLOR_NONE' + '$COLOR_GREEN_BOLD'ssh-agent'$COLOR_NONE
else
export SSH_AUTH_SOCK=/tmp/.ssh-socket
ssh-add -l >/dev/null 2>&1
if [[ $? = 2 ]]; then
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'Creating new ssh-agent'
rm -f /tmp/.ssh-script /tmp/.ssh-agent-pid /tmp/.ssh-socket
ssh-agent -a $SSH_AUTH_SOCK >/tmp/.ssh-script
. /tmp/.ssh-script
[[ $SH_INTERACTIVE ]] && echo $SSH_AGENT_PID >/tmp/.ssh-agent-pid
fi
fi
fi
if [[ $SH_OS_TYPE == OSX ]]; then
# Find the launchd-managed SSH agent socket (path changes each boot
# and after sleep/wake, so re-discover even inside tmux)
if [[ -z $SSH_AUTH_SOCK || ! -S $SSH_AUTH_SOCK ]]; then
local _mac_sock
# macOS 26+ moved sockets from /private/tmp to /var/run
_mac_sock=$(find /private/tmp /var/run -path "*/com.apple.launchd.*/Listeners" -user $USER 2>/dev/null | head -1)
if [[ -S "$_mac_sock" ]]; then
export SSH_AUTH_SOCK="$_mac_sock"
fi
fi
fi
if [[ $SH_OS_TYPE == Linux && -z $TMUX ]]; then
# Skip inside tmux; agent env vars are inherited from the pre-tmux shell
local _ssh_sock
_ssh_sock=$(find /tmp/ssh-* -name agent.\* 2>/dev/null | head -1)
if [[ -n "$(pgrep -u $USER ssh-agent)" && -S "$_ssh_sock" ]]; then
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'SSH agent '$COLOR_GREEN_BOLD'running'$COLOR_NONE'. Connecting...'
export SSH_AGENT_PID=$(pgrep -n -u $USER ssh-agent)
export SSH_AUTH_SOCK="$_ssh_sock"
elif [[ $SH_INTERACTIVE ]]; then
# Only kill/restart in interactive shells — non-interactive shells
# (scp, remote git, cron) must not disrupt running agents
echo
echo -e 'SSH agent '$COLOR_YELLOW_BOLD'not running'$COLOR_NONE'. Starting new one...'
pkill -u $USER ssh-agent 2>/dev/null
rm -rf /tmp/ssh-* 2>/dev/null
eval $(ssh-agent -s) >/dev/null
fi
fi
# Auto-attach to tmux on SSH login (before heavy init — tmux spawns a fresh shell).
# TMUX_AUTO_ATTACH=0 disables it.
# TMUX_AUTO_ATTACH_SESSION changes the base session (default: main).
# TMUX_AUTO_ATTACH_MODE=shared|auto|dedicated controls session sharing.
if [[ -n $SSH_CONNECTION && -z $TMUX && $- == *i* && $TMUX_AUTO_ATTACH != 0 ]]; then
if command -v tmux >/dev/null 2>&1; then
TMUX_ATTACH_SESSION=$(__tmux_auto_attach_target_session)
exec tmux new-session -As "$TMUX_ATTACH_SESSION"
fi
fi
# Add keys in all shells (not just interactive) so git commit signing works
# in non-interactive contexts like VS Code's built-in git
ssh-add >/dev/null 2>&1
if [[ -f "${HOME}/.ssh/id_rsa_personal" ]]; then
if [[ $(ssh-add -l 2>/dev/null | grep -i id_rsa_personal | wc -l) -lt 1 ]]; then
if [[ $SH_OS_TYPE == OSX ]]; then
ssh-add --apple-use-keychain ${HOME}/.ssh/id_rsa_personal >/dev/null 2>&1
else
ssh-add ${HOME}/.ssh/id_rsa_personal >/dev/null 2>&1
fi
fi
fi
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# Non-interactive shells (scp, remote git commands, cron) only need
# the SSH agent and basic env above — skip the rest to avoid latency
if [[ ! $SH_INTERACTIVE ]]; then
return
fi
HISTSIZE=10000
HISTFILESIZE=10000
# Source additional global, local, and personal definitions
[[ $SH_INTERACTIVE ]] && echo
__include_files "${HOME}/.bashrc.local" "${HOME}/.bashrc_local" "${SH_SOURCE_DIR}/aliases" "${HOME}/.aliases.local" "${HOME}/.aliases_local"
# ITerm2 integration
local ITERM2_INTEGRATION
if [[ $SH_OS_TYPE == OSX ]]; then
ITERM2_INTEGRATION=$HOME/.iterm2_shell_integration.bash
if [[ -f "$ITERM2_INTEGRATION" ]]; then
[[ $SH_INTERACTIVE ]] && echo -e 'Loading '$COLOR_YELLOW_BOLD$ITERM2_INTEGRATION$COLOR_NONE
. "$ITERM2_INTEGRATION"
fi
fi
# Bash completion
local BASH_COMPLETION_INSTALLED BASH_COMPLETION_INSTALLED_COMMAND
if [[ $SH_OS_TYPE == OSX ]]; then
BASH_COMPLETION_INSTALLED_COMMAND=_brew_completions
elif [[ $SH_OS_TYPE == Linux ]]; then
BASH_COMPLETION_INSTALLED_COMMAND=_init_completion
fi
BASH_COMPLETION_INSTALLED=$(type -t ${BASH_COMPLETION_INSTALLED_COMMAND})
if [[ -z $BASH_COMPLETION && -z $BASH_COMPLETION_INSTALLED ]]; then
if [[ $SH_OS_TYPE == OSX ]]; then
# Bash completion for Mac OS X (from Homebrew or MacPorts)
if [[ -f /usr/local/etc/bash_completion ]]; then
[[ $SH_INTERACTIVE ]] && echo -e 'Loading '$COLOR_YELLOW_BOLD'/usr/local/etc/bash_completion'$COLOR_NONE
. /usr/local/etc/bash_completion
elif [[ -f /opt/local/etc/profile.d/bash_completion.sh ]]; then
[[ $SH_INTERACTIVE ]] && echo -e 'Loading '$COLOR_YELLOW_BOLD'/opt/local/etc/profile.d/bash_completion.sh'$COLOR_NONE
. /opt/local/etc/profile.d/bash_completion.sh
elif [[ -f ${BREW_DIR}/bin/brew ]]; then
if [[ -f ${BREW_DIR}/etc/profile.d/bash_completion.sh ]]; then
[[ $SH_INTERACTIVE ]] && echo -e 'Loading '$COLOR_YELLOW_BOLD$BREW_DIR'/etc/profile.d/bash_completion.sh'$COLOR_NONE
. ${BREW_DIR}/etc/profile.d/bash_completion.sh
fi
fi
elif [[ $SH_OS_TYPE == Linux ]]; then
# Bash completion for Linux
if [[ -f /etc/bash_completion ]]; then
[[ $SH_INTERACTIVE ]] && echo -e 'Loading '$COLOR_YELLOW_BOLD'/etc/bash_completion'$COLOR_NONE
. /etc/bash_completion
fi
fi
BASH_COMPLETION_INSTALLED=$(type -t ${BASH_COMPLETION_INSTALLED_COMMAND})
if [[ -z $BASH_COMPLETION && -z $BASH_COMPLETION_INSTALLED ]]; then
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'Bash completion '$COLOR_RED_BOLD'not configured'$COLOR_NONE
fi
fi
# Git completion and prompt
local GIT_COMPLETION
if [[ -z $(type -t __git_ps1) ]]; then
GIT_COMPLETION=$(type -P git-completion.bash)
if [[ -z $GIT_COMPLETION ]]; then
GIT_COMPLETION=$HOME/bin/git-completion.bash
fi
if [[ -f "$GIT_COMPLETION" ]]; then
[[ $SH_INTERACTIVE ]] && echo -e 'Loading '$COLOR_YELLOW_BOLD$GIT_COMPLETION$COLOR_NONE
. "$GIT_COMPLETION"
fi
fi
if [[ -z $(type -t __git_ps1) ]]; then
if [[ -f /opt/homebrew/etc/bash_completion.d/git-prompt.sh ]]; then
. /opt/homebrew/etc/bash_completion.d/git-prompt.sh
fi
fi
# ADB completion
local ADB_COMPLETION
ADB_COMPLETION=$(type -P adb.bash)
if [[ -z $ADB_COMPLETION ]]; then
ADB_COMPLETION=$HOME/bin/adb.bash
fi
if [[ -f "$ADB_COMPLETION" ]]; then
[[ $SH_INTERACTIVE ]] && echo -e 'Loading '$COLOR_YELLOW_BOLD$ADB_COMPLETION$COLOR_NONE
. "$ADB_COMPLETION"
fi
local PATH_DIRS=("${HOME}/bin" "${HOME}/.local/bin" "${SH_SOURCE_DIR}/scripts")
if [[ $SH_OS_TYPE == OSX ]]; then
# Mac OS X paths, including Homebrew and MacPorts
PATH_DIRS=("${PATH_DIRS[@]}" "/usr/local/bin" "/usr/local/sbin" "/opt/local/bin" "/opt/local/sbin" "${BREW_DIR}/bin")
fi
if [[ $SH_OS_DISTRO == Ubuntu ]]; then
PATH_DIRS=("${PATH_DIRS[@]}" "/snap/bin")
fi
__add_to_path "${PATH_DIRS[@]}"
if [[ -n $BASH_COMPLETION_INSTALLED ]]; then
# Affects cd behavior
__add_to_cd_path "." "${HOME}" "${HOME}/src"
fi
# SSH client
if [[ -n $SSH_CLIENT ]]; then
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'Connected from '$COLOR_YELLOW_BOLD$(get_ssh_client_ip)$COLOR_NONE
if is_tailscale_ssh; then
[[ $SH_INTERACTIVE ]] && echo -e 'Connection via '$COLOR_GREEN_BOLD'Tailscale'$COLOR_NONE
fi
if [[ $SH_INTERACTIVE && $SH_OS_TYPE == OSX ]]; then
echo -e 'Unlocking '$COLOR_CYAN_BOLD'keychain'$COLOR_NONE'...'
security unlock-keychain
fi
fi
# Prompt
local COLOR_ROOT_INVERT VERSION_CONTROL_PROMPT
COLOR_ROOT_INVERT=$COLOR_GREEN_INVERT
if [[ "$(whoami)" == "root" ]]; then
COLOR_ROOT_INVERT=$COLOR_RED_INVERT
fi
# Show git branch in prompt
__version_control_ps1() {
if [[ -n $(type -t __git_ps1) ]]; then
__git_ps1 '[git %s] '
else
local branch
branch=$(git symbolic-ref --short HEAD 2>/dev/null)
[[ -n "$branch" ]] && printf '[git %s] ' "$branch"
fi
}
VERSION_CONTROL_PROMPT='$(__version_control_ps1)'
export PS1='\['$COLOR_BOLD'\]\['$COLOR_ROOT_INVERT'\]\u\['$COLOR_NONE'\] \['$COLOR_BOLD'\]\['$COLOR_YELLOW_INVERT'\]\h\['$COLOR_NONE'\] \['$COLOR_CYAN_BOLD'\]\w\['$COLOR_NONE'\] \['$COLOR_MAGENTA_BOLD'\]'$VERSION_CONTROL_PROMPT'\['$COLOR_NONE'\]\$ '
# Color directories
if [[ $SH_OS_TYPE == OSX ]]; then
# Mac OS X settings
#export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
fi
if [[ $SH_OS_TYPE == Linux ]]; then
# Linux settings
export LS_COLORS='di=01;36'
fi
# Misc declarations
if [[ $SH_OS_TYPE == Linux ]]; then
if [[ $SH_OS_DISTRO == Ubuntu ]]; then
if [[ -z $SHELL ]]; then
# Ubuntu does not always define it for some reason
export SHELL=/usr/bin/env bash
fi
fi
fi
export EDITOR=vim
# WSL X configuration
if [[ $SH_OS_FLAVOR == WSL ]]; then
export GDK_DPI_SCALE=2
fi
# Dev declarations
# Antigravity
if [[ -d $HOME/.antigravity/antigravity/bin ]]; then
__add_to_path "${HOME}/.antigravity/antigravity/bin"
elif [[ $SH_OS_FLAVOR == WSL ]]; then
# On WSL, Antigravity is installed under Windows user's AppData
__WSL_WIN_USER=$(cmd.exe /c "echo %USERNAME%" 2>/dev/null | tr -d '\r\n')
if [[ -n "$__WSL_WIN_USER" && -d "/mnt/c/Users/${__WSL_WIN_USER}/AppData/Local/Programs/Antigravity/bin" ]]; then
__add_to_path "/mnt/c/Users/${__WSL_WIN_USER}/AppData/Local/Programs/Antigravity/bin"
fi
unset __WSL_WIN_USER
fi
# Claude
if [[ -d $HOME/.claude/local ]]; then
__add_to_path "${HOME}/.claude/local"
fi
# Android SDK
if [[ -d $HOME/android-sdk ]]; then
export ANDROID_HOME=$HOME/android-sdk
fi
if [[ -d $HOME/Library/Android/sdk ]]; then
export ANDROID_HOME=$HOME/Library/Android/sdk
fi
if [[ -n $ANDROID_HOME ]]; then
__add_to_path "${ANDROID_HOME}/build-tools/$([[ -d "${ANDROID_HOME}/build-tools/" ]] && ls -1 "${ANDROID_HOME}/build-tools/" | tr -d '/' | sort -V | tail -n 1)" "${ANDROID_HOME}/platform-tools" "${ANDROID_HOME}/tools"
fi
if [[ -d $HOME/android-ndk ]]; then
export ANDROID_NDK=$HOME/android-ndk
fi
if [[ -d $ANDROID_HOME/ndk ]]; then
export ANDROID_NDK=$ANDROID_HOME/ndk
fi
if [[ -n $ANDROID_NDK ]]; then
export ANDROID_NDK_REPOSITORY=$ANDROID_NDK
export ANDROID_NDK_ROOT=$ANDROID_NDK
export NDKROOT=$ANDROID_NDK
export NDK_MODULE_PATH=$ANDROID_NDK
__add_to_path "${ANDROID_NDK}/$([[ -d "${ANDROID_NDK}/" ]] && ls -1 "${ANDROID_NDK}/" | tr -d '/' | sort -V | tail -n 1)"
fi
# Node
if [[ -d $HOME/.nvm ]]; then
export NVM_DIR="$HOME/.nvm"
fi
if [[ -d $NVM_DIR ]]; then
if [[ -s "$NVM_DIR/nvm.sh" ]]; then
. "$NVM_DIR/nvm.sh"
fi
if [[ -s "$NVM_DIR/bash_completion" ]]; then
. "$NVM_DIR/bash_completion"
fi
fi
# Bun
if [[ -d $HOME/.bun ]]; then
export BUN_INSTALL="$HOME/.bun"
fi
if [[ -d $BUN_INSTALL ]]; then
__add_to_path "${BUN_INSTALL}/bin"
fi
# Ruby
local SH_BREW_RUBY SH_DEFAULT_GEM_HOME
if [[ $SH_OS_TYPE == OSX ]]; then
SH_BREW_RUBY="${BREW_DIR}/opt/ruby/bin/ruby"
if [[ -x $SH_BREW_RUBY ]]; then
__add_to_path "${BREW_DIR}/opt/ruby/bin"
SH_DEFAULT_GEM_HOME=$($SH_BREW_RUBY -e 'require "rubygems"; print Gem.default_dir' 2>/dev/null)
fi
fi
if [[ -z $GEM_HOME ]]; then
if [[ -n $SH_DEFAULT_GEM_HOME && -d $SH_DEFAULT_GEM_HOME ]]; then
export GEM_HOME="$SH_DEFAULT_GEM_HOME"
elif [[ -d $HOME/.gem ]]; then
export GEM_HOME="$HOME/.gem"
elif [[ -d $HOME/gems ]]; then
export GEM_HOME="$HOME/gems"
fi
fi
if [[ -n $GEM_HOME ]]; then
__add_to_path "${GEM_HOME}/bin"
fi
# Go
if [[ $SH_OS_TYPE == OSX ]]; then
if [[ -d $HOME/go ]]; then
export GOPATH=$HOME/go
fi
fi
# Conda
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('$HOME/miniconda3/bin/conda' 'shell.bash' 'hook' 2>/dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
fi
unset __conda_setup
# <<< conda initialize <<<
# uv
if [[ -f "$HOME/.local/bin/env" ]]; then
. "$HOME/.local/bin/env"
fi
# Rust
if [[ -f $HOME/.cargo/env ]]; then
. "$HOME/.cargo/env"
fi
# CUDA
if [[ -d /usr/local/cuda/bin ]]; then
__add_to_path "/usr/local/cuda/bin"
fi
# CUDA / Llama.cpp
if [[ $SH_OS_DISTRO == Ubuntu && -d /usr/local/cuda ]]; then
export CUDA_HOME=/usr/local/cuda
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
export GGML_CUDA_ENABLE_UNIFIED_MEMORY=1
fi
# >>> nvwb
# Sourcing the nvwb wrapper function was added during the NVIDIA AI Workbench installation and
# is required for NVIDIA AI Workbench to function properly. When uninstalling
# NVIDIA AI Workbench, it will be removed.
if [[ -f "$HOME/.local/share/nvwb/nvwb-wrapper.sh" ]]; then
source "$HOME/.local/share/nvwb/nvwb-wrapper.sh"
fi
# >>> nvwb
# Local declarations
if [[ -n $(type -t __bashrc_local_run) ]]; then
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'Executing '$COLOR_YELLOW_BOLD$(__bashrc_local)$COLOR_NONE
__bashrc_local_run "$@"
fi
# Global aliases deferred load
if [[ -n $(type -t __aliases_load) ]]; then
__aliases_load "$@"
fi
# Local aliases deferred load
if [[ -n $(type -t __aliases_local_load) ]]; then
__aliases_local_load "$@"
fi
# Global dotrc deferred load
# Node
# After local dotrc to ensure we don't pick accidentally local dotrc node version
if [[ -d $NVM_DIR ]]; then
if [[ $(nvm current) == system ]]; then
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'Switching node from '$COLOR_YELLOW_BOLD'system'$COLOR_NONE' to '$COLOR_YELLOW_BOLD'nvm default'$COLOR_NONE
nvm use default
fi
fi
# Free space
local FREE_SPACE FREE_SPACE_READABLE
FREE_SPACE=$(df -k / | tail -n 1 | awk '{printf $4}')
FREE_SPACE_READABLE=$(df -h / | tail -n 1 | awk '{printf $4}' | tr -d i)
FREE_SPACE_READABLE=$COLOR_YELLOW_BOLD$FREE_SPACE_READABLE$COLOR_NONE
if (($FREE_SPACE <= 5000000)); then
FREE_SPACE_READABLE=$FREE_SPACE_READABLE' '$COLOR_RED_BOLD'WARNING: Low free disk space!!!'$COLOR_NONE
fi
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'Free space: '$FREE_SPACE_READABLE
[[ $SH_INTERACTIVE ]] && echo
}
__bashrc_main "$@"
unset -f __bashrc_main