mirror of
https://github.com/NixOS/nix.git
synced 2024-11-21 22:32:26 +00:00
Add a zsh completion script
Based on @clhodapp's suggestion in https://github.com/spwhitt/nix-zsh-completions/issues/32#issuecomment-705315356 and adapted to use the description of the completions
This commit is contained in:
parent
04e5d0e704
commit
eea310b241
21
misc/zsh/completion.zsh
Normal file
21
misc/zsh/completion.zsh
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
function _nix() {
|
||||||
|
local ifs_bk="$IFS"
|
||||||
|
local input=("${(Q)words[@]}")
|
||||||
|
IFS=$'\n'
|
||||||
|
local res=($(NIX_GET_COMPLETIONS=$((CURRENT - 1)) "$input[@]"))
|
||||||
|
IFS="$ifs_bk"
|
||||||
|
local tpe="${${res[1]}%%> *}"
|
||||||
|
local -a suggestions
|
||||||
|
declare -a suggestions
|
||||||
|
for suggestion in ${res:1}; do
|
||||||
|
# FIXME: This doesn't work properly if the suggestion word contains a `:`
|
||||||
|
# itself
|
||||||
|
suggestions+="${suggestion/ /:}"
|
||||||
|
done
|
||||||
|
if [[ "$tpe" == filenames ]]; then
|
||||||
|
compadd -f
|
||||||
|
fi
|
||||||
|
_describe 'nix' suggestions
|
||||||
|
}
|
||||||
|
|
||||||
|
compdef _nix nix
|
Loading…
Reference in New Issue
Block a user