-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot_zshrc.tmpl
More file actions
327 lines (275 loc) · 11 KB
/
Copy pathdot_zshrc.tmpl
File metadata and controls
327 lines (275 loc) · 11 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
# ============================================================================
# ZSH Configuration
# ============================================================================
# Completion System Setup
setopt prompt_subst
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
autoload bashcompinit && bashcompinit
autoload -Uz compinit
compinit
# ============================================================================
# Zinit Plugin Manager
# ============================================================================
{{- if eq .chezmoi.os "darwin" }}
# macOS: Source Zinit from Homebrew (supports both Apple Silicon and Intel)
if [[ -f /opt/homebrew/opt/zinit/zinit.zsh ]]; then
# Apple Silicon
source /opt/homebrew/opt/zinit/zinit.zsh
source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh
source /opt/homebrew/share/zsh-fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
source /opt/homebrew/share/zsh-autopair/autopair.zsh
elif [[ -f /usr/local/opt/zinit/zinit.zsh ]]; then
# Intel Mac
source /usr/local/opt/zinit/zinit.zsh
source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh
source /usr/local/share/zsh-fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
source /usr/local/share/zsh-autopair/autopair.zsh
fi
{{- else }}
# Linux: Self-managed Zinit installation
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
[ ! -d $ZINIT_HOME ] && mkdir -p "$(dirname $ZINIT_HOME)"
[ ! -d $ZINIT_HOME/.git ] && git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
source "${ZINIT_HOME}/zinit.zsh"
# Load plugins via Zinit
zinit light zsh-users/zsh-autosuggestions
zinit light zdharma-continuum/fast-syntax-highlighting
zinit light hlissner/zsh-autopair
{{- end }}
# Removed zsh-autocomplete - it's incompatible with menu-complete tab cycling
# Configure tab for cycling through completions (standard ZSH completion)
bindkey '\t' menu-complete
bindkey "$terminfo[kcbt]" reverse-menu-complete
# Enable menu selection with highlighting
zstyle ':completion:*' menu select
zstyle ':completion:*' list-colors ''
# ============================================================================
# Key Bindings
# ============================================================================
# Autosuggestions key bindings
bindkey '^w' autosuggest-execute
bindkey '^e' autosuggest-accept
bindkey '^u' autosuggest-toggle
bindkey '^k' up-line-or-search
bindkey '^j' down-line-or-search
# ============================================================================
# Environment Variables
# ============================================================================
export LANG=en_US.UTF-8
{{- if and (hasKey . "is_headless") .is_headless }}
export EDITOR="nvim"
export VISUAL="nvim"
{{- else }}
# Mac: Zed for $EDITOR. `zed` must be on PATH (brew cask installs it
# automatically; manual installs need Zed.app menu → "Install CLI").
# `--wait` blocks until the editor closes the file — required for git commits.
export EDITOR="zed --wait"
export VISUAL="zed --wait"
{{- end }}
export GOPATH="$HOME/go"
export XDG_CONFIG_HOME="$HOME/.config"
# Herdr panes run under the host terminal's PTY. When the host is Ghostty, let
# pane applications use Ghostty's terminfo instead of Herdr's generic fallback.
if [[ -n "$HERDR_ENV" && "$TERM_PROGRAM" == "ghostty" ]] && infocmp xterm-ghostty >/dev/null 2>&1; then
export TERM="xterm-ghostty"
fi
# Clipboard CLI wrapper - reads theme fresh each time for runtime theme switching
cb() {
[[ -f "$XDG_CONFIG_HOME/clipboard/theme" ]] && export CLIPBOARD_THEME="$(cat "$XDG_CONFIG_HOME/clipboard/theme")"
command cb "$@"
}
# FZF shell integration
# Ctrl-T = file picker — free across the WM/ghostty/herdr stack on both OSes.
# Ctrl-R is reclaimed by atuin (initialized below). Alt-C (cd widget) is
# intentionally disabled: Alt/Option+C is reserved for copy, and yazi (y) +
# zoxide already cover directory navigation.
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
command -v fzf >/dev/null && source <(fzf --zsh)
bindkey -r '\ec' # unbind Alt-C (fzf-cd-widget); reserved for copy
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# Television is installed but kept as optional tool
# Not used in functions due to terminal compatibility issues
# ============================================================================
# Aliases
# ============================================================================
# Editor
alias e="nvim"
{{- if not .is_headless }}
alias v="neovide"
{{- end }}
# Modern CLI replacements
alias cat="bat"
alias l="eza -l --icons --git -a"
alias lt="eza --tree --level=2 --long --icons --git -a"
alias ltree="eza --tree --level=2 --icons --git -a"
alias la="tree"
alias cl="clear"
# Directory navigation
alias ~="cd ~"
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ......="cd ../../../../.."
# Git aliases
alias gc="git commit -m"
alias gca="git commit -a -m"
alias gp="git push origin HEAD"
alias gpu="git pull origin"
alias gst="git status"
alias glog="git log --graph --topo-order --pretty='%w(100,0,6)%C(yellow)%h%C(bold)%C(black)%d %C(cyan)%ar %C(green)%an%n%C(bold)%C(white)%s %N' --abbrev-commit"
alias gdiff="git diff"
alias gco="git checkout"
alias gb="git branch"
alias gba="git branch -a"
alias gadd="git add"
alias ga="git add -p"
alias gcoall="git checkout -- ."
alias gr="git remote"
alias gre="git reset"
# Docker aliases (when Docker is installed)
alias dco="docker compose"
alias dps="docker ps"
alias dpa="docker ps -a"
alias dl="docker ps -l -q"
alias dx="docker exec -it"
# Tools
alias http="xh"
alias lg="lazygit"
# Arabic text reading (fribidi for proper RTL display)
alias acat="fribidi" # Read Arabic from stdin/pipe
alias ar="fribidi" # Short alias for Arabic reading
# Television aliases for quick access
alias tvf="tv files" # Quick file search
alias tvd="tv dirs" # Quick directory search
alias tvg="tv git-repos" # Find git repositories
alias tvh="tv zsh-history" # Search zsh history
{{- if eq .chezmoi.os "darwin" }}
# macOS terminal clock — pin tty-clock to the primary accent (ANSI slot 2 =
# the theme-system's Material primary; mirrors peaclock's green on Linux).
alias tty-clock="tty-clock -C 2"
{{- end }}
# Remote Machines
{{- if .tailscale_enabled }}
# Raw mosh access to the dev host
alias devhub="mosh {{ .chezmoi.username }}@{{ .tailscale_hosts.dev_hub }}"
{{- end }}
# ============================================================================
# Functions
# ============================================================================
# Change directory and list contents
cx() { cd "$@" && l; }
# Fuzzy find directory and cd into it
fcd() {
local dir=$(find . -type d -not -path '*/.*' | fzf --preview 'eza -la --color=always {}')
[ -n "$dir" ] && cd "$dir" && l
}
# Fuzzy find file and copy path to clipboard
f() {
local file=$(find . -type f -not -path '*/.*' | fzf --preview 'bat --color=always {}')
{{- if eq .chezmoi.os "darwin" }}
[ -n "$file" ] && echo "$file" | pbcopy
{{- else }}
[ -n "$file" ] && echo "$file" | wl-copy || xclip -selection clipboard
{{- end }}
}
{{- if not .is_headless }}
# Fuzzy find file and open in Neovide (GUI only)
fv() {
local file=$(find . -type f -not -path '*/.*' | fzf --preview 'bat --color=always {}')
[ -n "$file" ] && neovide "$file"
}
{{- end }}
{{- if eq .chezmoi.os "darwin" }}
# Fuzzy find and focus aerospace window (macOS only)
ff() {
aerospace list-windows --all | fzf | awk '{print $1}' | xargs -I {} aerospace focus --window-id {}
}
{{- end }}
# Yazi with directory change on exit
function y() {
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")"
yazi "$@" --cwd-file="$tmp"
if cwd="$(command cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
cd -- "$cwd"
fi
rm -f -- "$tmp"
}
# Read Arabic file with proper RTL display
# Usage: afile filename.txt
function afile() {
if [ -z "$1" ]; then
echo "Usage: afile <filename>"
return 1
fi
command cat "$1" | fribidi | less -R
}
# Tail Arabic logs with proper RTL display
# Usage: atail filename.log
function atail() {
if [ -z "$1" ]; then
echo "Usage: atail <filename>"
return 1
fi
tail -f "$1" | fribidi
}
# ============================================================================
# Tool Initializations
# ============================================================================
# Starship prompt
command -v starship &>/dev/null && eval "$(starship init zsh)"
export STARSHIP_CONFIG=~/.config/starship/starship.toml
# Atuin shell history
[ -f "$HOME/.atuin/bin/env" ] && . "$HOME/.atuin/bin/env"
command -v atuin &>/dev/null && eval "$(atuin init zsh)"
# Zoxide smart cd
command -v zoxide &>/dev/null && eval "$(zoxide init zsh)"
# ============================================================================
# Completions
# ============================================================================
# Load completions if available
if command -v kubectl &> /dev/null; then
source <(kubectl completion zsh)
fi
if command -v aws &> /dev/null && command -v aws_completer &> /dev/null; then
complete -C "$(command -v aws_completer)" aws
fi
# Display system info on terminal startup
command -v fastfetch &>/dev/null && fastfetch --config examples/13
{{- if eq .chezmoi.os "darwin" }}
# macOS PATH additions (Homebrew, .local/bin, .cargo/bin already set by zprofile/zshenv)
export PATH="$HOME/.bun/bin:$HOME/.atuin/bin:$HOME/go/bin:/Applications/Ghostty.app/Contents/MacOS:$PATH"
# Python user packages (version-agnostic)
for pydir in "$HOME/Library/Python"/*/bin(N); do
[[ -d "$pydir" ]] && export PATH="$pydir:$PATH"
done
# Zed CLI is on PATH via /opt/homebrew/bin/zed (symlink → Zed.app/Contents/MacOS/cli)
# installed automatically by `brew install --cask zed`. No alias needed.
{{- else }}
# Linux PATH additions (minimal - .local/bin already in zshenv handles pip packages)
export PATH="$HOME/.bun/bin:$HOME/.atuin/bin:$HOME/go/bin:$PATH"
{{- end }}
alias ascii="~/scripts/figlet.sh"
alias theme="~/.config/theme-system/scripts/theme-manager.py"
alias wallpaper="~/.config/theme-system/scripts/wallpaper-manager.py"
alias secrets="~/scripts/secrets.sh && source ~/.secrets"
# pnpm
export PNPM_HOME="/home/malhashemi/.local/share/pnpm"
case ":$PATH:" in
*":$PNPM_HOME:"*) ;;
*) export PATH="$PNPM_HOME:$PATH" ;;
esac
# pnpm end
setopt INTERACTIVE_COMMENTS
# CF CLI completions — guarded with [[ -f ]] so it no-ops if `cf` isn't installed.
[[ -f "$HOME/.config/cf/completions/_cf.zsh" ]] && source "$HOME/.config/cf/completions/_cf.zsh"
# worktrunk (`wt`) — git worktree CLI for parallel agent workflows.
# Self-guarded with `command -v` so it no-ops on machines that don't have it.
if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)"; fi
{{- if .is_linux }}
# Linuxbrew (Homebrew for Linux)
if [[ -d /home/linuxbrew/.linuxbrew ]]; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv zsh)"
fi
{{- end }}