This is a simpe start to bash completions for opkg. Initialy, this can
complete current supported verbs (static) and complete package names
(dynamic).

Signed-off-by: Jacob Stiffler <[email protected]>
---
 .../recipes-devtools/opkg/opkg-bash-completion.bb  | 15 +++++++++++++
 .../opkg/opkg-bash-completion/opkg-bash-completion | 26 ++++++++++++++++++++++
 2 files changed, 41 insertions(+)
 create mode 100644 
meta-arago-extras/recipes-devtools/opkg/opkg-bash-completion.bb
 create mode 100644 
meta-arago-extras/recipes-devtools/opkg/opkg-bash-completion/opkg-bash-completion

diff --git a/meta-arago-extras/recipes-devtools/opkg/opkg-bash-completion.bb 
b/meta-arago-extras/recipes-devtools/opkg/opkg-bash-completion.bb
new file mode 100644
index 0000000..74e4964
--- /dev/null
+++ b/meta-arago-extras/recipes-devtools/opkg/opkg-bash-completion.bb
@@ -0,0 +1,15 @@
+SUMMARY = "bash-completions for opkg"
+LICENSE = "MIT"
+
+LIC_FILES_CHKSUM = 
"file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
+
+SRC_URI = "file://opkg-bash-completion"
+
+do_install() {
+    install -d ${D}${datadir}/bash-completion/completions
+    install -m 0644 ${WORKDIR}/opkg-bash-completion \
+                    ${D}${datadir}/bash-completion/completions/opkg
+}
+
+FILES_${PN} = "${datadir}/bash-completion/completions/opkg"
+RDEPENDS_${PN} = "bash-completion"
diff --git 
a/meta-arago-extras/recipes-devtools/opkg/opkg-bash-completion/opkg-bash-completion
 
b/meta-arago-extras/recipes-devtools/opkg/opkg-bash-completion/opkg-bash-completion
new file mode 100644
index 0000000..5b0b4e1
--- /dev/null
+++ 
b/meta-arago-extras/recipes-devtools/opkg/opkg-bash-completion/opkg-bash-completion
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+# TBD: parse "opkg --help" to get this list
+OPKG_COMMANDS="update upgrade install configure remove clean flag list 
list-installed list-upgradable list-changed-conffiles files search find info 
status download compare-versions print-architecture depends whatdepends 
whatdependsrec whatrecommends whatsuggests whatprovides whatconflicts 
whatreplaces"
+
+_opkg_completions() {
+    if [ ${#COMP_WORDS[@]} -eq 2 ]
+    then
+        COMPREPLY=($(compgen -W "${OPKG_COMMANDS}" "${COMP_WORDS[1]}"))
+        return
+    fi
+
+    # TBD: add more cases, support options
+    case "${COMP_WORDS[1]}" in
+        install|files|info|status|download)
+            COMPREPLY=($(compgen -W "$(opkg list | sed -e 's| .*$||')" -- 
"${COMP_WORDS[$COMP_CWORD]}"));;
+        
depends|whatdepends|whatdependsrec|whatrecommends|whatsuggests|whatprovides|whatconflicts|whatreplaces)
+            COMPREPLY=($(compgen -W "-A $(opkg list | sed -e 's| .*$||')" -- 
"${COMP_WORDS[$COMP_CWORD]}"));;
+        remove)
+            COMPREPLY=($(compgen -W "$(opkg list-installed | sed -e 's| 
.*$||')" -- "${COMP_WORDS[$COMP_CWORD]}"));;
+        upgrade)
+            COMPREPLY=($(compgen -W "$(opkg list-upgradable | sed -e 's| 
.*$||')" -- "${COMP_WORDS[$COMP_CWORD]}"));;
+    esac
+}
+
+complete -F _opkg_completions opkg
-- 
2.7.4

_______________________________________________
meta-arago mailing list
[email protected]
http://arago-project.org/cgi-bin/mailman/listinfo/meta-arago

Reply via email to