From 9f973a623de9e381d01bd6702d898dcab18affb0 Mon Sep 17 00:00:00 2001
From: Moul <moul@moul.re>
Date: Sat, 5 Jan 2019 23:23:21 +0100
Subject: [PATCH] =?UTF-8?q?[enh]=20#166:=C2=A0add=20bash=20and=20zsh=20com?=
 =?UTF-8?q?pletion=20scripts?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 shell_completion/silkaj-bash-complete.sh | 21 ++++++++++++++++++
 shell_completion/silkaj-zsh-complete.sh  | 28 ++++++++++++++++++++++++
 2 files changed, 49 insertions(+)
 create mode 100644 shell_completion/silkaj-bash-complete.sh
 create mode 100644 shell_completion/silkaj-zsh-complete.sh

diff --git a/shell_completion/silkaj-bash-complete.sh b/shell_completion/silkaj-bash-complete.sh
new file mode 100644
index 00000000..843b529a
--- /dev/null
+++ b/shell_completion/silkaj-bash-complete.sh
@@ -0,0 +1,21 @@
+_silkaj_completion() {
+    local IFS=$'
+'
+    COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \
+                   COMP_CWORD=$COMP_CWORD \
+                   _SILKAJ_COMPLETE=complete $1 ) )
+    return 0
+}
+
+_silkaj_completionetup() {
+    local COMPLETION_OPTIONS=""
+    local BASH_VERSION_ARR=(${BASH_VERSION//./ })
+    # Only BASH version 4.4 and later have the nosort option.
+    if [ ${BASH_VERSION_ARR[0]} -gt 4 ] || ([ ${BASH_VERSION_ARR[0]} -eq 4 ] && [ ${BASH_VERSION_ARR[1]} -ge 4 ]); then
+        COMPLETION_OPTIONS="-o nosort"
+    fi
+
+    complete $COMPLETION_OPTIONS -F _silkaj_completion silkaj
+}
+
+_silkaj_completionetup;
diff --git a/shell_completion/silkaj-zsh-complete.sh b/shell_completion/silkaj-zsh-complete.sh
new file mode 100644
index 00000000..3667592f
--- /dev/null
+++ b/shell_completion/silkaj-zsh-complete.sh
@@ -0,0 +1,28 @@
+_silkaj_completion() {
+    local -a completions
+    local -a completions_with_descriptions
+    local -a response
+    response=("${(@f)$( env COMP_WORDS="${words[*]}" \
+                        COMP_CWORD=$((CURRENT-1)) \
+                        _SILKAJ_COMPLETE="complete_zsh" \
+                        silkaj )}")
+
+    for key descr in ${(kv)response}; do
+      if [[ "$descr" == "_" ]]; then
+          completions+=("$key")
+      else
+          completions_with_descriptions+=("$key":"$descr")
+      fi
+    done
+
+    if [ -n "$completions_with_descriptions" ]; then
+        _describe -V unsorted completions_with_descriptions -U -Q
+    fi
+
+    if [ -n "$completions" ]; then
+        compadd -U -V unsorted -Q -a completions
+    fi
+    compstate[insert]="automenu"
+}
+
+compdef _silkaj_completion silkaj;
-- 
GitLab