From: Jacob Stiffler <[email protected]>

* This is a simpe start to bash completions for opkg. Initialy, this can
  complete current supported verbs (static) and complete package names
  (dynamic).
* Use helpers (e.g. _init_completion, _count_args) to enhance usability
* Add support for search and flag verbs

Signed-off-by: Jacob Stiffler <[email protected]>
Signed-off-by: Denys Dmytriyenko <[email protected]>
---
 .../packagegroups/packagegroup-arago-base.bb       |  1 +
 .../recipes-devtools/opkg/opkg-bash-completion.bb  | 17 +++++++
 .../opkg/opkg-bash-completion/opkg-bash-completion | 53 ++++++++++++++++++++++
 3 files changed, 71 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-distro/recipes-core/packagegroups/packagegroup-arago-base.bb 
b/meta-arago-distro/recipes-core/packagegroups/packagegroup-arago-base.bb
index 4094d90..e3f1916 100644
--- a/meta-arago-distro/recipes-core/packagegroups/packagegroup-arago-base.bb
+++ b/meta-arago-distro/recipes-core/packagegroups/packagegroup-arago-base.bb
@@ -20,6 +20,7 @@ ARAGO_BASE = "\
     ethtool \
     thermal-init \
     bash \
+    opkg-bash-completion \
     udev-extraconf \
     "
 
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..6055507
--- /dev/null
+++ b/meta-arago-extras/recipes-devtools/opkg/opkg-bash-completion.bb
@@ -0,0 +1,17 @@
+SUMMARY = "bash-completions for opkg"
+LICENSE = "MIT"
+
+PR = "r1"
+
+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..82b6c6f
--- /dev/null
+++ 
b/meta-arago-extras/recipes-devtools/opkg/opkg-bash-completion/opkg-bash-completion
@@ -0,0 +1,53 @@
+#!/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_FLAGS="hold noprune user ok installed unpacked"
+OPKG_LONGOPTS="--help --verbosity --conf --dest --offline-root --add-arch 
--add-dest --add-exclude --add-ignore-recommends --prefer-arch-to-version 
--combine --force-depends --force-maintainer --force-reinstall 
--force-overwrite --force-downgrade --force-space --force-postinstall 
--force-remove --force-checksum --noaction --size --download-only --nodeps 
--no-install-recommends --force-removal-of-dependent-packages --autoremove 
--tmp-dir --lists-dir --cache-dir --host-cache-dir --volatile-cache"
+
+_opkg_completions() {
+    # Use this helpful helper to beautify things and catch vars and redirects
+    local cur prev words cword
+    _init_completion -s || return 0
+
+    # Catch options first
+    if [[ "$cur" == -* ]]
+    then
+        COMPREPLY=($(compgen -W "${OPKG_LONGOPTS}" -- "$cur"))
+        return
+    fi
+
+    # Now catch args
+    # opkg supports a single verb, so that will be the first arg,
+    local arg args
+    _get_first_arg
+    _count_args
+
+    case "$arg" in
+        install|files|info|status|download)
+            COMPREPLY=($(compgen -W "$(opkg list | sed -e 's| .*$||')" -- 
"$cur"));;
+        
depends|whatdepends|whatdependsrec|whatrecommends|whatsuggests|whatprovides|whatconflicts|whatreplaces)
+            COMPREPLY=($(compgen -W "-A $(opkg list | sed -e 's| .*$||')" -- 
"$cur"));;
+        remove)
+            COMPREPLY=($(compgen -W "$(opkg list-installed | sed -e 's| 
.*$||')" -- "$cur"));;
+        upgrade)
+            COMPREPLY=($(compgen -W "$(opkg list-upgradable | sed -e 's| 
.*$||')" -- "$cur"));;
+        flag)
+            if [ $args -eq 2 ]
+            then
+                COMPREPLY=($(compgen -W "${OPKG_FLAGS}" "$cur"))
+            else
+                COMPREPLY=($(compgen -W "-A $(opkg list | sed -e 's| .*$||')" 
-- "$cur"))
+            fi
+            ;;
+        search)
+            # Only search for a single file
+            [ $args -gt 2 ] || _longopt;;
+        "")
+            COMPREPLY=($(compgen -W "${OPKG_COMMANDS}" -- "$cur"));;
+        *)
+            COMPREPLY=( "*" "I DONT KNOW WHAT TO DO!!!" )
+    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