summaryrefslogtreecommitdiffstats
path: root/misc
diff options
context:
space:
mode:
authorregnat <rg@regnat.ovh>2020-10-09 09:41:55 +0200
committerregnat <rg@regnat.ovh>2020-10-09 09:47:47 +0200
commiteea310b2418e30280ae5fd9dac54ffe7f3c5dafa (patch)
tree38bf2bc18e2cd578a51e40e43b213b9fd195fbcc /misc
parent04e5d0e7040fdfbbc084634c0694ae7da89765d9 (diff)
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
Diffstat (limited to 'misc')
-rw-r--r--misc/zsh/completion.zsh21
1 files changed, 21 insertions, 0 deletions
diff --git a/misc/zsh/completion.zsh b/misc/zsh/completion.zsh
new file mode 100644
index 000000000..d4df6447e
--- /dev/null
+++ b/misc/zsh/completion.zsh
@@ -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