Repository navigation
Expand file tree
/
Copy pathdot_shellrc
More file actions
227 lines (207 loc) · 9.72 KB
/
Copy pathdot_shellrc
File metadata and controls
227 lines (207 loc) · 9.72 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
#!/usr/bin/env sh
# IMPORTANT: Managed by chezmoi - do not edit this copy directly.
# Source: ~/.local/share/chezmoi - edit there, then run `chezmoi apply`.
# If you edit this file directly, notify the user and reconcile with the chezmoi source.
# ----------------------------------------------------------------------------
# shellrc is sourced by both .bashrc and .zshrc
# Keep this file POSIX-compatible (no bash or zsh specific syntax)
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Prompt (shell-agnostic)
# ----------------------------------------------------------------------------
# _PROMPT_ID = user@host color: red for root, magenta for remote (SSH), cyan for local
# green = no dotfiles installed (system default) — intentionally unused here
# _PROMPT_INFO = path color: always blue
# _PROMPT_RESET = reset color
if [ "$(id -u)" = "0" ]; then
_PROMPT_ID=$(printf '\033[1;31m') # bold red (root)
elif [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ] || [ -n "$SSH_CONNECTION" ]; then
_PROMPT_ID=$(printf '\033[1;35m') # bold magenta (remote)
else
_PROMPT_ID=$(printf '\033[1;36m') # bold cyan (local)
fi
_PROMPT_INFO=$(printf '\033[34m') # blue (path)
_PROMPT_RESET=$(printf '\033[0m') # reset
# ----------------------------------------------------------------------------
# Colors (shell-agnostic)
# ----------------------------------------------------------------------------
# BSD ls (macOS): CLICOLOR enables color, LSCOLORS defines the scheme
# Format: each pair = fg/bg for: dir symlink socket pipe exec block char setuid setgid sticky-dir other-writable-dir
export CLICOLOR=1
export LSCOLORS="ExGxFxDxCxEgEdxbxgxcxd" # bold: blue dir, cyan link, magenta socket, green exec
# LS_COLORS: used by GNU ls, grep, fd, tree, and many other tools
if command -v dircolors >/dev/null 2>&1; then
eval "$(dircolors -b)"
else
# Fallback for macOS (no dircolors): sensible defaults for tools that read LS_COLORS
export LS_COLORS='di=1;34:ln=1;36:so=1;35:pi=33:ex=1;32:bd=1;33:cd=1;33:su=37;41:sg=30;43:tw=30;42:ow=34;42'
fi
# Colorize commands that support "--color=auto"
alias grep='grep --color=auto'
if diff --color=auto /dev/null /dev/null >/dev/null 2>&1; then
alias diff='diff --color=auto'
fi
if ls --color=auto /dev/null >/dev/null 2>&1; then
alias ls='ls --color=auto'
fi
# ----------------------------------------------------------------------------
# Editor (shell-agnostic)
# ----------------------------------------------------------------------------
export EDITOR=vim
# ----------------------------------------------------------------------------
# History (shell-agnostic)
# ----------------------------------------------------------------------------
export HISTSIZE=10000
# ----------------------------------------------------------------------------
# cheatsheet lookup (shell-agnostic)
# See docs/cheatsheets/ — files use .sh extension for GitHub syntax highlighting
# ----------------------------------------------------------------------------
cheatsheet() {
local dir="$HOME/.local/share/chezmoi/docs/cheatsheets"
if [ -z "$1" ]; then
echo "Usage:"
echo " cheatsheet <topic>"
echo ""
echo "Available cheatsheets:"
ls "$dir" | sed 's/\.sh$//' | sed 's/^/ /'
elif [ -f "$dir/$1.sh" ]; then
cat "$dir/$1.sh"
else
echo "No cheatsheet found for '$1'. Run 'cheatsheet' to list available topics."
return 1
fi
}
# ----------------------------------------------------------------------------
# Reload shell config without exiting (shell-agnostic)
# ----------------------------------------------------------------------------
reload() {
echo "Reloading shell..."
case "$(ps -p $$ -o comm=)" in
*zsh*) exec zsh ;;
*bash*) exec bash ;;
*) echo "Unknown shell; restart manually." ;;
esac
}
# ----------------------------------------------------------------------------
# OPTIONAL: Homebrew (shell-agnostic)
# ----------------------------------------------------------------------------
# /etc/paths.d/homebrew puts /opt/homebrew/bin on PATH, but path_helper APPENDS
# it — after /usr/bin — so `git` resolved to Apple's 2.50.1 instead of
# Homebrew's 2.53.0. The problem is ordering, not presence: brew itself was
# always findable. Prepending is the whole fix.
#
# `brew shellenv` would also do this, but it costs ~10ms and two subprocesses on
# every shell start, and the other four things it sets are unused here: nothing
# runs compinit (so its zsh `fpath` line feeds nothing), and nothing reads
# HOMEBREW_PREFIX, MANPATH or INFOPATH. Re-check that before switching back.
#
# Placed above the $HOME/.local/bin block on purpose, so that block stays AHEAD
# of Homebrew — the order it had when path_helper appended Homebrew last. It is
# not the front of PATH overall (pyenv, fnm and bun all prepend further down);
# the only invariant being preserved here is .local/bin > /opt/homebrew/bin.
if [ -d /opt/homebrew/bin ]; then
export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$PATH"
fi
# ----------------------------------------------------------------------------
# OPTIONAL: PATH (shell-agnostic)
# ----------------------------------------------------------------------------
# Add $HOME/.local/bin to front of PATH (if exists)
test -d "$HOME/.local/bin" && export PATH="$HOME/.local/bin:$PATH"
# ----------------------------------------------------------------------------
# OPTIONAL: pyenv (shell-agnostic)
# ----------------------------------------------------------------------------
if [ -d "$HOME/.pyenv" ]; then
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
fi
# ----------------------------------------------------------------------------
# OPTIONAL: fnm (shell-agnostic)
# ----------------------------------------------------------------------------
if command -v fnm >/dev/null 2>&1; then
eval "$(fnm env)"
fi
# ----------------------------------------------------------------------------
# OPTIONAL: nvm (shell-agnostic)
# ----------------------------------------------------------------------------
if [ -s "/opt/homebrew/opt/nvm/nvm.sh" ]; then
export NVM_DIR="$HOME/.nvm"
\. "/opt/homebrew/opt/nvm/nvm.sh"
elif [ -s "/usr/local/opt/nvm/nvm.sh" ]; then
export NVM_DIR="$HOME/.nvm"
\. "/usr/local/opt/nvm/nvm.sh"
fi
# ----------------------------------------------------------------------------
# OPTIONAL: Go (shell-agnostic)
# ----------------------------------------------------------------------------
# Keeps Go's state out of $HOME. Go already moved GOCACHE and GOENV to
# macOS-appropriate locations on its own but deliberately left GOPATH at ~/go;
# these two finish the job, and ~/go stops being created at all.
#
# GOPATH holds the module cache — GOMODCACHE follows it automatically, so it
# does not need setting separately.
#
# GOBIN sends `go install` binaries to ~/.local/bin, which the PATH block above
# already covers, so Go contributes no PATH entry of its own. This mirrors what
# uv already does here: payloads under ~/.local/share/<tool>, entry points in
# ~/.local/bin.
#
# Set unconditionally — no `command -v go` guard, and no test that the dirs
# exist. Two reasons. These decide where Go WILL put things, so the paths are
# meant to be absent until first use; and guarding on Go being installed would
# defeat the purpose on a fresh machine, where the shell starts before Go is
# installed and the first `go install` would then create ~/go after all. Two
# env vars with no Go present are inert.
#
# Deliberately not `go env -w`, which persists to a machine-local file
# (~/Library/Application Support/go/env) that would not travel with these
# dotfiles.
export GOPATH="$HOME/.local/share/go"
export GOBIN="$HOME/.local/bin"
# ----------------------------------------------------------------------------
# OPTIONAL: bun (shell-agnostic)
# ----------------------------------------------------------------------------
if [ -d "$HOME/.bun" ]; then
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
# completions are zsh-specific
case "$(ps -p $$ -o comm=)" in
*zsh*) [ -s "$BUN_INSTALL/_bun" ] && \. "$BUN_INSTALL/_bun" ;;
esac
fi
# ----------------------------------------------------------------------------
# OPTIONAL: ssh-agent - requires smallstep (shell-agnostic)
# ----------------------------------------------------------------------------
if command -v step >/dev/null 2>&1; then
if ! pgrep -u "$USER" ssh-agent >/dev/null 2>&1; then
eval "$(ssh-agent -s)" >/dev/null
fi
fi
# ----------------------------------------------------------------------------
# OPTIONAL: fzf (shell-agnostic)
# Fuzzy finder: powers Ctrl-R history search, Ctrl-T file/Alt-C dir widgets,
# and zoxide's interactive `zi` picker. No POSIX integration; zsh/bash only.
# ----------------------------------------------------------------------------
if command -v fzf >/dev/null 2>&1; then
case "$(ps -p $$ -o comm=)" in
*zsh*) eval "$(fzf --zsh)" ;;
*bash*) eval "$(fzf --bash)" ;;
esac
fi
# ----------------------------------------------------------------------------
# OPTIONAL: zoxide (shell-agnostic)
# ----------------------------------------------------------------------------
if command -v zoxide >/dev/null 2>&1; then
case "$(ps -p $$ -o comm=)" in
*zsh*) eval "$(zoxide init zsh)" ;;
*bash*) eval "$(zoxide init bash)" ;;
*) eval "$(zoxide init posix --hook prompt)" ;;
esac
fi
# ----------------------------------------------------------------------------
# OPTIONAL: Kitty terminal (shell-agnostic)
# Use kitten ssh to propagate terminfo to remote hosts
# ----------------------------------------------------------------------------
if command -v kitten >/dev/null 2>&1; then
alias ssh='kitten ssh'
fi