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 | |
| parent | 8d9be9a56f514276e1b448f744378ea8c0d1f875 (diff) | |
| download | dotfiles-4ca1eccea079d6464619c8e9080f562737b521bb.tar.gz dotfiles-4ca1eccea079d6464619c8e9080f562737b521bb.zip | |
feat(zsh): add completion generation and consolidate path config
| -rw-r--r-- | flake.lock | 24 | ||||
| -rw-r--r-- | modules/home/zsh.nix | 69 |
2 files changed, 63 insertions, 30 deletions
@@ -24,11 +24,11 @@ ] }, "locked": { - "lastModified": 1775217257, - "narHash": "sha256-3m79jjgeNoK7JxhPrmNLGWI0vrZ1gtBCe3qWmijplYU=", + "lastModified": 1777042514, + "narHash": "sha256-8dQRRZzeJhlxVI4i38icAqsHIZ4d8N0uPeJod5UBKeU=", "owner": "dinacomputer", "repo": "cli", - "rev": "4ddd97559fa6dfd2e4b3a4ccea634c16a40a0274", + "rev": "13aa1b986824d30a1ab1fcdca1bad5dcac537b62", "type": "github" }, "original": { @@ -62,11 +62,11 @@ ] }, "locked": { - "lastModified": 1774007980, - "narHash": "sha256-FOnZjElEI8pqqCvB6K/1JRHTE8o4rer8driivTpq2uo=", + "lastModified": 1777258755, + "narHash": "sha256-EC07KwADRE2LdIk7vEDyAaD3I0ZUq24T9jQF9L0iEPk=", "owner": "nix-community", "repo": "home-manager", - "rev": "9670de2921812bc4e0452f6e3efd8c859696c183", + "rev": "7f8bbc93d63401e41368d6ddc46a4f631610fa90", "type": "github" }, "original": { @@ -82,11 +82,11 @@ ] }, "locked": { - "lastModified": 1773000227, - "narHash": "sha256-zm3ftUQw0MPumYi91HovoGhgyZBlM4o3Zy0LhPNwzXE=", + "lastModified": 1775037210, + "narHash": "sha256-KM2WYj6EA7M/FVZVCl3rqWY+TFV5QzSyyGE2gQxeODU=", "owner": "LnL7", "repo": "nix-darwin", - "rev": "da529ac9e46f25ed5616fd634079a5f3c579135f", + "rev": "06648f4902343228ce2de79f291dd5a58ee12146", "type": "github" }, "original": { @@ -97,11 +97,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1773840656, - "narHash": "sha256-9tpvMGFteZnd3gRQZFlRCohVpqooygFuy9yjuyRL2C0=", + "lastModified": 1776949667, + "narHash": "sha256-GMSVw35Q+294GlrTUKlx087E31z7KurReQ1YHSKp5iw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "9cf7092bdd603554bd8b63c216e8943cf9b12512", + "rev": "01fbdeef22b76df85ea168fbfe1bfd9e63681b30", "type": "github" }, "original": { 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 + ''; } |
