[PATCH 2/2] pwclient: add bash completion for project names

Yann E. MORIN yann.morin.1998 at free.fr
Sun Jun 29 05:32:13 EST 2014


From: "Yann E. MORIN" <yann.morin.1998 at free.fr>

Add initial bash-completion, which so far only completes on the
project names.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998 at free.fr>

---
It should work with any version of bash-completion, although I have only
tested it with bash-completion 2.0. The main change in bash-completion
2.0 is the addition of _init_completion that is responsible for initialising
the variables, which must be done manualy otherwise.
---
 apps/patchwork/bin/bash_completion | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 apps/patchwork/bin/bash_completion

diff --git a/apps/patchwork/bin/bash_completion b/apps/patchwork/bin/bash_completion
new file mode 100644
index 0000000..a120a76
--- /dev/null
+++ b/apps/patchwork/bin/bash_completion
@@ -0,0 +1,29 @@
+# Autocompletion for bash.
+
+_pwclient() {
+    local cur prev words cword split
+
+    if declare -f _init_completion >/dev/null; then
+        _init_completion -s || return
+    else
+        cur=$(_get_cword)
+        prev=${COMP_WORDS[COMP_CWORD-1]}
+    fi
+
+    case "${COMP_CWORD}" in
+        0|1)    return 0;;
+    esac
+
+    projects="$(sed -r -e '/\[options\]/d;' \
+                       -e '/^\[(.+)\]$/!d;' \
+                       -e 's//\1/;' ~/.pwclientrc 2>/dev/null)"
+
+    case "${prev}" in
+        -p) COMPREPLY=( $(compgen -W "${projects}" -- "${cur}" ) );;
+    esac
+
+    return 0
+}
+complete -F _pwclient pwclient
+
+# vim: ft=sh
-- 
1.8.3.2



More information about the Patchwork mailing list