aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
Diffstat (limited to 'misc')
-rw-r--r--misc/bash/completion.sh5
-rw-r--r--misc/zsh/completion.zsh21
2 files changed, 24 insertions, 2 deletions
diff --git a/misc/bash/completion.sh b/misc/bash/completion.sh
index bc184edd6..bea2a40bc 100644
--- a/misc/bash/completion.sh
+++ b/misc/bash/completion.sh
@@ -4,13 +4,14 @@ function _complete_nix {
_get_comp_words_by_ref -n ':=&' words cword cur
local have_type
while IFS= read -r line; do
+ local completion=${line%% *}
if [[ -z $have_type ]]; then
have_type=1
- if [[ $line = filenames ]]; then
+ if [[ $completion = filenames ]]; then
compopt -o filenames
fi
else
- COMPREPLY+=("$line")
+ COMPREPLY+=("$completion")
fi
done < <(NIX_GET_COMPLETIONS=$cword "${words[@]}")
__ltrim_colon_completions "$cur"
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