diff options
| author | 2026-05-14 11:25:43 +0100 | |
|---|---|---|
| committer | 2026-05-14 11:25:43 +0100 | |
| commit | 89829b5beaad70aa58cd566bd975aafcfe8d1f8f (patch) | |
| tree | 8beb36e495d6136c763b0260c13c204f67a5a407 /dot_config | |
| parent | f1936454ebe39f4c2b0214c4b16624209a3e4503 (diff) | |
| download | dotfiles-89829b5beaad70aa58cd566bd975aafcfe8d1f8f.tar.gz dotfiles-89829b5beaad70aa58cd566bd975aafcfe8d1f8f.tar.bz2 dotfiles-89829b5beaad70aa58cd566bd975aafcfe8d1f8f.zip | |
fix(zsh): make compdef guard check completion fn, also wire nix-profile fpath
Previous guard checked `$+commands[Y]` (binary present in PATH), but the
`compdef: unknown command or service: Y` message comes from compdef when
the *completion function* `_Y` isn't registered — on the remote-dev VM
`systemctl`, `just`, `lsd` are all on PATH yet zsh has no `_systemctl`
because Ubuntu's system zsh doesn't include nix-profile's
share/zsh/site-functions in fpath.
Two-part fix:
1. Prepend $HOME/.nix-profile/share/zsh/{site-functions,vendor-completions}
to fpath (when they exist) before compinit, so the completions get
loaded on the VM the same way they do on Arch.
2. Switch the compdef guard to `$+_comps[Y]` — the assoc-array compinit
actually populates with every command that has a registered completion
handler. Still belt-and-suspenders in case something ships a binary
without a matching completion file.
Diffstat (limited to 'dot_config')
| -rw-r--r-- | dot_config/zsh/dot_zshrc | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/dot_config/zsh/dot_zshrc b/dot_config/zsh/dot_zshrc index 97bb6ac..f5c3337 100644 --- a/dot_config/zsh/dot_zshrc +++ b/dot_config/zsh/dot_zshrc @@ -42,6 +42,13 @@ PROMPT='%B%{$fg[green]%}%n%{$reset_color%}@%{$fg[cyan]%}%m%{$reset_color%}:%b%{$ # ── Completion ──────────────────────────────────────────────────────────────── fpath=($XDG_DATA_HOME/zsh/completion $fpath) +# Pick up completions shipped by nix-installed packages on the remote-dev VM +# (Ubuntu's system zsh doesn't add the nix-profile share dirs to fpath). +for _d in "$HOME/.nix-profile/share/zsh/site-functions" \ + "$HOME/.nix-profile/share/zsh/vendor-completions"; do + [[ -d $_d ]] && fpath=($_d $fpath) +done +unset _d autoload -Uz compinit && compinit -d "$XDG_CACHE_HOME/zsh/zcompdump" zstyle ':completion:*' menu select # arrow-key driven menu for ambiguous completions @@ -344,16 +351,20 @@ alias gdbr='gdb -ex start --args' alias copilot='gh copilot --autopilot --enable-all-github-mcp-tools --yolo --resume' # ── Alias completions ───────────────────────────────────────────────────────── -# Guard each compdef on the target command being installed; otherwise zsh -# prints `compdef: unknown command or service: foo` on every login (e.g. on -# minimal remote-dev VMs where `just`/`lsd` aren't part of the system). +# Guard each compdef on the target's completion function actually being +# loaded; otherwise zsh prints `compdef: unknown command or service: foo` +# on every login (the binary being present isn't enough — the zsh +# completion file `_foo` must be in fpath and registered by compinit). +# Notably triggers on the remote-dev VM where nix-installed packages +# ship completions into /home/.../share/zsh/site-functions but Ubuntu's +# system zsh doesn't add that path to fpath by default. # Usage: _dot_compdef <target-cmd> <alias>=<target> [<alias>=<target>...] -_dot_compdef() { (( $+commands[$1] )) && compdef "${@:2}" } -_dot_compdef git g=git -_dot_compdef just j=just -_dot_compdef nvim n=nvim ndiff=nvim nd=nvim nview=nvim nv=nvim +_dot_compdef() { (( $+_comps[$1] )) && compdef "${@:2}" } +_dot_compdef git g=git +_dot_compdef just j=just +_dot_compdef nvim n=nvim ndiff=nvim nd=nvim nview=nvim nv=nvim _dot_compdef systemctl sys=systemctl ssys=systemctl sysu=systemctl -_dot_compdef lsd l=lsd la=lsd lt=lsd +_dot_compdef lsd l=lsd la=lsd lt=lsd unfunction _dot_compdef # ── GPG agent ───────────────────────────────────────────────────────────────── |
