Skip to content

Commit fab6b65

Browse files
committed
fix(zsh): avoid chezmoi include rewriting command checks
1 parent 5545e38 commit fab6b65

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

dot_config/zsh/split/plugins.zsh

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ zinit light romkatv/powerlevel10k
3939
# =============================================================================
4040
# Tool initialization (turbo mode)
4141
# =============================================================================
42+
# NOTE: `chezmoi`'s `include` rendering rewrites `${+commands[...]}` in this file
43+
# into invalid arithmetic syntax in the generated `~/.zshrc`, so use `command -v`.
4244
_zsh_cache="${XDG_CACHE_HOME}/zsh/init"
4345
[[ -d "$_zsh_cache" ]] || mkdir -p "$_zsh_cache"
4446

4547
# zoxide (turbo)
4648
_zinit_setup_zoxide() {
47-
if (( ${+commands[zoxide]} )); then
49+
if command -v zoxide >/dev/null 2>&1; then
4850
local _zoxide_cache="${XDG_CACHE_HOME}/zsh/init/zoxide.zsh"
4951
[[ -f "$_zoxide_cache" ]] || zoxide init zsh >"$_zoxide_cache"
5052
source "$_zoxide_cache"
@@ -57,7 +59,7 @@ zinit wait"1" lucid light-mode for \
5759

5860
# atuin (turbo) - shell history (load after fzf to override Ctrl+R)
5961
_zinit_setup_atuin() {
60-
if (( ${+commands[atuin]} )); then
62+
if command -v atuin >/dev/null 2>&1; then
6163
local _atuin_cache="${XDG_CACHE_HOME}/zsh/init/atuin.zsh"
6264
[[ -f "$_atuin_cache" ]] || atuin init zsh --disable-up-arrow >"$_atuin_cache"
6365
source "$_atuin_cache"
@@ -70,7 +72,7 @@ zinit wait"2" lucid light-mode for \
7072

7173
# fzf (turbo)
7274
_zinit_setup_fzf() {
73-
if (( ${+commands[fzf]} )); then
75+
if command -v fzf >/dev/null 2>&1; then
7476
local _fzf_cache="${XDG_CACHE_HOME}/zsh/init/fzf.zsh"
7577
[[ -f "$_fzf_cache" ]] || fzf --zsh >"$_fzf_cache"
7678
source "$_fzf_cache"
@@ -105,7 +107,7 @@ zinit wait"1" lucid light-mode for \
105107

106108
# direnv (turbo)
107109
_zinit_setup_direnv() {
108-
if (( ${+commands[direnv]} )); then
110+
if command -v direnv >/dev/null 2>&1; then
109111
local _direnv_cache="${XDG_CACHE_HOME}/zsh/init/direnv.zsh"
110112
[[ -f "$_direnv_cache" ]] || direnv hook zsh >"$_direnv_cache"
111113
source "$_direnv_cache"
@@ -127,42 +129,42 @@ _zinit_setup_completions() {
127129
local cache_dir="${XDG_CACHE_HOME}/zsh/completions"
128130

129131
# gh (GitHub CLI)
130-
if (( ${+commands[gh]} )); then
132+
if command -v gh >/dev/null 2>&1; then
131133
local _gh_comp="$cache_dir/_gh"
132134
[[ -f "$_gh_comp" ]] || gh completion -s zsh >"$_gh_comp"
133135
source "$_gh_comp"
134136
fi
135137

136138
# chezmoi
137-
if (( ${+commands[chezmoi]} )); then
139+
if command -v chezmoi >/dev/null 2>&1; then
138140
local _chezmoi_comp="$cache_dir/_chezmoi"
139141
[[ -f "$_chezmoi_comp" ]] || chezmoi completion zsh >"$_chezmoi_comp"
140142
source "$_chezmoi_comp"
141143
fi
142144

143145
# just
144-
if (( ${+commands[just]} )); then
146+
if command -v just >/dev/null 2>&1; then
145147
local _just_comp="$cache_dir/_just"
146148
[[ -f "$_just_comp" ]] || just --completions zsh >"$_just_comp"
147149
source "$_just_comp"
148150
fi
149151

150152
# mise
151-
if (( ${+commands[mise]} )); then
153+
if command -v mise >/dev/null 2>&1; then
152154
local _mise_comp="$cache_dir/_mise"
153155
[[ -f "$_mise_comp" ]] || mise completion zsh >"$_mise_comp"
154156
source "$_mise_comp"
155157
fi
156158

157159
# pnpm
158-
if (( ${+commands[pnpm]} )); then
160+
if command -v pnpm >/dev/null 2>&1; then
159161
local _pnpm_comp="$cache_dir/_pnpm"
160162
[[ -f "$_pnpm_comp" ]] || pnpm completion zsh >"$_pnpm_comp"
161163
source "$_pnpm_comp"
162164
fi
163165

164166
# kubectl
165-
if (( ${+commands[kubectl]} )); then
167+
if command -v kubectl >/dev/null 2>&1; then
166168
local _kubectl_comp="$cache_dir/_kubectl"
167169
[[ -f "$_kubectl_comp" ]] || kubectl completion zsh >"$_kubectl_comp"
168170
source "$_kubectl_comp"

0 commit comments

Comments
 (0)