-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.botenv
More file actions
146 lines (130 loc) · 4.73 KB
/
Copy path.botenv
File metadata and controls
146 lines (130 loc) · 4.73 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
# .botenv — Non-interactive-safe core bootstrap for botfiles.
#
# This file sets up the minimal environment (secrets, PATH, EDITOR, TERM,
# UV_BIN) needed by any shell context: interactive terminals, SSH commands,
# agent exec paths, cron jobs, and non-interactive hooks.
#
# It is POSIX-compatible and safe for both bash and zsh. The interactive
# layer (.botrc) should source this file and then add aliases, prompts,
# and other interactive-only configuration on top.
#
# Double-source guard: idempotent within the current shell.
if [ "${_BOTENV_LOADED:-0}" = "1" ]; then
return 0 2>/dev/null || exit 0
fi
# --- Resolve BOTFILES_ROOT from this file's own location ---------------
if [ -n "${BASH_SOURCE:-}" ]; then
_botenv_source="${BASH_SOURCE[0]}"
elif [ -n "${ZSH_VERSION:-}" ]; then
_botenv_source="${(%):-%x}"
else
# Plain /bin/sh: $0 is the shell binary, not this file. Fall back to
# the canonical botfiles location.
_botenv_source="$HOME/pro/botfiles/.botenv"
fi
BOTFILES_ROOT="$(cd "$(dirname "$_botenv_source")" && pwd)"
export BOTFILES_ROOT
unset _botenv_source
# --- Source local secrets in a fixed, deterministic order ---------------
if [ -d "$BOTFILES_ROOT/secrets/local" ]; then
for _botenv_secret in \
"$BOTFILES_ROOT/secrets/local/machine.rc" \
"$BOTFILES_ROOT/secrets/local/linear.rc" \
"$BOTFILES_ROOT/secrets/local/claude-bedrock.rc" \
"$BOTFILES_ROOT/secrets/local/claude-vertex.rc" \
"$BOTFILES_ROOT/secrets/local/gemini.rc" \
"$BOTFILES_ROOT/secrets/local/codex-azure.rc" \
"$BOTFILES_ROOT/secrets/local/codex-openai.rc" \
"$BOTFILES_ROOT/secrets/local/deep-research.rc" \
"$BOTFILES_ROOT/secrets/local/deep-feed.rc" \
"$BOTFILES_ROOT/secrets/local/opencode-azure.rc" \
"$BOTFILES_ROOT/secrets/local/claude-hooks.rc"; do
[ -f "$_botenv_secret" ] && . "$_botenv_secret"
done
unset _botenv_secret
fi
# --- Default editor for CLI tools (Codex, git, etc.) -------------------
if command -v nvim >/dev/null 2>&1; then
_botenv_default_editor=nvim
elif [ -x /opt/homebrew/bin/nvim ]; then
_botenv_default_editor=/opt/homebrew/bin/nvim
elif [ -x /home/linuxbrew/.linuxbrew/bin/nvim ]; then
_botenv_default_editor=/home/linuxbrew/.linuxbrew/bin/nvim
elif [ -x /usr/local/bin/nvim ]; then
_botenv_default_editor=/usr/local/bin/nvim
else
_botenv_default_editor=vim
fi
case "${EDITOR:-}" in
""|vim|*/vim) export EDITOR="$_botenv_default_editor" ;;
*) export EDITOR ;;
esac
case "${VISUAL:-}" in
""|vim|*/vim) export VISUAL="$EDITOR" ;;
*) export VISUAL ;;
esac
case "${GIT_EDITOR:-}" in
""|vim|*/vim) export GIT_EDITOR="$EDITOR" ;;
*) export GIT_EDITOR ;;
esac
unset _botenv_default_editor
# --- Normalize TERM for headless or unsupported terminal types ----------
# Ink- and curses-based CLIs (Claude Code, ranger, etc.) need a valid TERM
# that exists in the remote terminfo database.
_botenv_term_fallback=xterm-256color
if [ -z "${TERM:-}" ] || [ "$TERM" = "dumb" ]; then
export TERM="$_botenv_term_fallback"
elif command -v infocmp >/dev/null 2>&1; then
if ! infocmp "$TERM" >/dev/null 2>&1; then
export TERM="$_botenv_term_fallback"
fi
fi
unset _botenv_term_fallback
# --- PATH: normalize shared bin directories in the intended order ------
_botenv_path_rest=""
_botenv_old_ifs=$IFS
IFS=:
for _botenv_path_entry in ${PATH:-}; do
case "$_botenv_path_entry" in
"$BOTFILES_ROOT/bin"|"$HOME/.local/bin"|"/opt/homebrew/bin"|"/opt/homebrew/sbin"|"/home/linuxbrew/.linuxbrew/bin"|"/home/linuxbrew/.linuxbrew/sbin"|"/usr/local/bin"|"/usr/local/sbin") ;;
"")
;;
*)
if [ -n "$_botenv_path_rest" ]; then
_botenv_path_rest="${_botenv_path_rest}:$_botenv_path_entry"
else
_botenv_path_rest="$_botenv_path_entry"
fi
;;
esac
done
IFS=$_botenv_old_ifs
unset _botenv_old_ifs _botenv_path_entry
_botenv_path_prefix="$BOTFILES_ROOT/bin:$HOME/.local/bin"
for _botenv_path_entry in \
/opt/homebrew/bin \
/opt/homebrew/sbin \
/home/linuxbrew/.linuxbrew/bin \
/home/linuxbrew/.linuxbrew/sbin \
/usr/local/bin \
/usr/local/sbin; do
if [ -d "$_botenv_path_entry" ]; then
_botenv_path_prefix="$_botenv_path_prefix:$_botenv_path_entry"
fi
done
unset _botenv_path_entry
if [ -n "$_botenv_path_rest" ]; then
PATH="$_botenv_path_prefix:$_botenv_path_rest"
else
PATH="$_botenv_path_prefix"
fi
export PATH
unset _botenv_path_prefix _botenv_path_rest
# --- UV_BIN resolution -------------------------------------------------
if [ -f "$BOTFILES_ROOT/shell/10-uv-bin.sh" ]; then
. "$BOTFILES_ROOT/shell/10-uv-bin.sh"
fi
# --- Mark loaded -------------------------------------------------------
_BOTENV_LOADED=1
# Keep this shell-local so child shells still evaluate .botenv through
# BASH_ENV/zshenv instead of inheriting a stale "already loaded" marker.