diff mbox

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

Message ID b53b822df5efcc529a695edbea0b3fd3863757be.1403983801.git.yann.morin.1998@free.fr
State Superseded
Headers show

Commit Message

Yann E. MORIN June 28, 2014, 7:32 p.m. UTC
From: "Yann E. MORIN" <yann.morin.1998@free.fr>

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

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@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 mbox

Patch

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