13082bb159361d1c0807eb7e5577f4c670cb0f88

Author
Till Backhaus <tback@users.noreply.github.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(watson): add completion (#10886)

Co-authored-by: Carlo Sala <carlosalag@protonmail.com>

Diff

 1diff --git a/plugins/watson/README.md b/plugins/watson/README.md
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..ef734ec635b9cfc713cbeff17e605aee1d3efeb4
 4--- /dev/null
 5+++ b/plugins/watson/README.md
 6@@ -0,0 +1,9 @@
 7+# Watson
 8+
 9+This plugin provides completion for [Watson](https://tailordev.github.io/Watson/).
10+
11+To use it add `watson` to the plugins array in your zshrc file.
12+
13+```zsh
14+plugins=(... watson)
15+```
16diff --git a/plugins/watson/_watson b/plugins/watson/_watson
17new file mode 100644
18index 0000000000000000000000000000000000000000..0f599bd665ac5ae3cbe9453bd710361c4abd3e5b
19--- /dev/null
20+++ b/plugins/watson/_watson
21@@ -0,0 +1,34 @@
22+#compdef watson
23+
24+_watson_completion() {
25+    local -a completions
26+    local -a completions_with_descriptions
27+    local -a response
28+    (( ! $+commands[watson] )) && return 1
29+
30+    response=("${(@f)$(env COMP_WORDS="${words[*]}" COMP_CWORD=$((CURRENT-1)) _WATSON_COMPLETE=zsh_complete watson)}")
31+
32+    for type key descr in ${response}; do
33+        if [[ "$type" == "plain" ]]; then
34+            if [[ "$descr" == "_" ]]; then
35+                completions+=("$key")
36+            else
37+                completions_with_descriptions+=("$key":"$descr")
38+            fi
39+        elif [[ "$type" == "dir" ]]; then
40+            _path_files -/
41+        elif [[ "$type" == "file" ]]; then
42+            _path_files -f
43+        fi
44+    done
45+
46+    if [ -n "$completions_with_descriptions" ]; then
47+        _describe -V unsorted completions_with_descriptions -U
48+    fi
49+
50+    if [ -n "$completions" ]; then
51+        compadd -U -V unsorted -a completions
52+    fi
53+}
54+
55+compdef _watson_completion watson;