Files
lix/misc/zsh/completion.zsh
Matthew Bauerandjade 65ef28df6d completions: Show description in zsh completions
Uses the second part of NIX_GET_COMPLETIONS if available.

Change-Id: I35efaaea3f35eea25a8de723ab32ceecd054e7df
Fixes: https://git.lix.systems/lix-project/lix/issues/910
2025-07-11 02:54:08 +00:00

29 lines
809 B
Bash

#compdef nix
function _nix() {
local input=("${(Q)words[@]}")
local -a suggestions # what value to actually use on completion
local -a suggestions_display # what to display to the user
local tpe suggestion description
local ifs_bk="$IFS"
IFS=$'\t'
NIX_GET_COMPLETIONS=$((CURRENT - 1)) "$input[@]" 2>/dev/null | {read tpe; while IFS=$'\t' read -r suggestion description; do
suggestions+=("$suggestion")
if [ -n "$description" ]; then
suggestions_display+=("$suggestion -- $description")
else
suggestions_display+=("$suggestion")
fi
done}
IFS="$ifs_bk"
local -a args
if [[ "$tpe" == filenames ]]; then
args+=('-f')
elif [[ "$tpe" == attrs ]]; then
args+=('-S' '')
fi
compadd -J nix "${args[@]}" -d suggestions_display -a suggestions
}
_nix "$@"