diff options
| author | Simen A. W. Olsen <hello@simenandre.no> | 2026-04-29 15:04:36 +0200 |
|---|---|---|
| committer | Simen A. W. Olsen <hello@simenandre.no> | 2026-04-29 15:04:36 +0200 |
| commit | 4ca1eccea079d6464619c8e9080f562737b521bb (patch) | |
| tree | dd6f30bc39d666100b4027c7bc9bde1156b08e7d /modules | |
| parent | 8d9be9a56f514276e1b448f744378ea8c0d1f875 (diff) | |
| download | dotfiles-4ca1eccea079d6464619c8e9080f562737b521bb.tar.gz dotfiles-4ca1eccea079d6464619c8e9080f562737b521bb.zip | |
feat(zsh): add completion generation and consolidate path config
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/home/zsh.nix | 69 |
1 files changed, 51 insertions, 18 deletions
diff --git a/modules/home/zsh.nix b/modules/home/zsh.nix index a968be0..a2d5809 100644 --- a/modules/home/zsh.nix +++ b/modules/home/zsh.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: +{ pkgs, lib, ... }: let zsh-autocomplete = pkgs.fetchFromGitHub { @@ -40,11 +40,18 @@ in # Ensure path arrays do not contain duplicates. typeset -gU path fpath + # Cached zsh completions generated on rebuild (see home.activation in zsh.nix). + fpath=($HOME/.zsh_completions $fpath) + # Set the list of directories that zsh searches for commands. path=( $HOME/{,s}bin(N) $HOME/.local/{,s}bin(N) $HOME/.cargo/bin(N) + $HOME/go/bin(N) + /Library/Frameworks/Firebird.framework/Resources/bin(N) + /opt/homebrew/opt/libpq/bin(N) + /opt/homebrew/opt/rustup/bin(N) /opt/{homebrew,local}/{,s}bin(N) /usr/local/{,s}bin(N) $path @@ -65,7 +72,7 @@ in # shellcheck disable=SC1090 # sourced filenames with variables # Remove stale compiled zsh files that shadow nix-managed configs - rm -f ~/.config/zsh/.zshrc.zwc ~/.config/zsh/{aliases,path,extras}.zwc + rm -f ~/.config/zsh/.zshrc.zwc ~/.config/zsh/{aliases,extras}.zwc function set_terminal_title() { printf '\033]0;%s@%s:%s\033\\' "$USER" "''${HOST%%.*}" "''${PWD/#$HOME/~}" @@ -86,7 +93,7 @@ in source ~/.zsh_repos/jeffreytse/zsh-vi-mode/zsh-vi-mode.plugin.zsh - for file in ~/.config/zsh/{aliases,path,extras}; do + for file in ~/.config/zsh/{aliases,extras}; do if [[ -r "$file" ]] && [[ -f "$file" ]]; then # shellcheck source=/dev/null source "$file" @@ -107,6 +114,9 @@ in alias ls='ls --color' '' + (if pkgs.stdenv.isDarwin then '' alias tailscale='/Applications/Tailscale.app/Contents/MacOS/Tailscale' + alias rebuild='sudo darwin-rebuild switch --flake ~/ghq/github.com/simenandre/dotfiles#default' + alias update='nix flake update --flake ~/ghq/github.com/simenandre/dotfiles && sudo darwin-rebuild switch --flake ~/ghq/github.com/simenandre/dotfiles#default' + alias nix-gc='sudo nix-collect-garbage --delete-older-than 14d && nix-collect-garbage --delete-older-than 14d && nix store gc' '' else "") + '' # Generic / Random / Utility @@ -143,21 +153,6 @@ in alias dump-issues="getBjerkIssues > ~/Downloads/issues-$(date -I).json" ''; - ".config/zsh/path".text = '' - #!/bin/bash - - # Add directories to the PATH and prevent to add the same directory multiple times upon shell reload. - add_to_path() { - if [[ -d "$1" ]] && [[ ":$PATH:" != *":$1:"* ]]; then - export PATH="$1:$PATH" - fi - } - - add_to_path "/Library/Frameworks/Firebird.framework/Resources/bin" - add_to_path "/opt/homebrew/opt/libpq/bin" - add_to_path "$HOME/go/bin" - ''; - ".config/zsh/extras".text = '' if [[ "$(uname)" == "Darwin" ]]; then export DOCKER_HOST="unix://$HOME/.colima/default/docker.sock" @@ -200,4 +195,42 @@ in } ''; }; + + home.activation.generateZshCompletions = lib.hm.dag.entryAfter [ "writeBoundary" ] '' + COMPDIR="$HOME/.zsh_completions" + $DRY_RUN_CMD mkdir -p "$COMPDIR" + + # Make brew-installed binaries discoverable during activation. + export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$HOME/.cargo/bin:$HOME/go/bin:$PATH" + + generate() { + local name="$1" + local bin="$2" + shift 2 + if command -v "$bin" >/dev/null 2>&1; then + if "$bin" "$@" > "$COMPDIR/_$name.tmp" 2>/dev/null && [ -s "$COMPDIR/_$name.tmp" ]; then + mv "$COMPDIR/_$name.tmp" "$COMPDIR/_$name" + else + rm -f "$COMPDIR/_$name.tmp" + echo " warning: failed to generate _$name (does '$bin' support 'completion zsh'?)" + fi + fi + } + + generate gh gh completion -s zsh + generate kubectl kubectl completion zsh + generate helm helm completion zsh + generate pulumi pulumi gen-completion zsh + generate bun bun completions zsh + generate pnpm pnpm completion zsh + generate deno deno completions zsh + generate flyctl flyctl completion zsh + generate rustup rustup completions zsh + generate cargo rustup completions zsh cargo + generate robin robin completion zsh + generate dina dina completion zsh + generate so so completion zsh + generate dinactl dinactl completion zsh + generate identityctl identityctl completion zsh + ''; } |
