* Use helpers (e.g. _init_completion, _count_args) to enhance usability
* Add support for search and flag verbs

Signed-off-by: Jacob Stiffler <j-stiff...@ti.com>
---
 .../recipes-devtools/opkg/opkg-bash-completion.bb  |  2 +
 .../opkg/opkg-bash-completion/opkg-bash-completion | 43 ++++++++++++++++++----
 2 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/meta-arago-extras/recipes-devtools/opkg/opkg-bash-completion.bb 
b/meta-arago-extras/recipes-devtools/opkg/opkg-bash-completion.bb
index 74e4964..6055507 100644
--- a/meta-arago-extras/recipes-devtools/opkg/opkg-bash-completion.bb
+++ b/meta-arago-extras/recipes-devtools/opkg/opkg-bash-completion.bb
@@ -1,6 +1,8 @@
 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"
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
index 5b0b4e1..82b6c6f 100644
--- 
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
@@ -2,24 +2,51 @@
 
 # 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() {
-    if [ ${#COMP_WORDS[@]} -eq 2 ]
+    # 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_COMMANDS}" "${COMP_WORDS[1]}"))
+        COMPREPLY=($(compgen -W "${OPKG_LONGOPTS}" -- "$cur"))
         return
     fi
 
-    # TBD: add more cases, support options
-    case "${COMP_WORDS[1]}" in
+    # 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| .*$||')" -- 
"${COMP_WORDS[$COMP_CWORD]}"));;
+            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| .*$||')" -- 
"${COMP_WORDS[$COMP_CWORD]}"));;
+            COMPREPLY=($(compgen -W "-A $(opkg list | sed -e 's| .*$||')" -- 
"$cur"));;
         remove)
-            COMPREPLY=($(compgen -W "$(opkg list-installed | sed -e 's| 
.*$||')" -- "${COMP_WORDS[$COMP_CWORD]}"));;
+            COMPREPLY=($(compgen -W "$(opkg list-installed | sed -e 's| 
.*$||')" -- "$cur"));;
         upgrade)
-            COMPREPLY=($(compgen -W "$(opkg list-upgradable | sed -e 's| 
.*$||')" -- "${COMP_WORDS[$COMP_CWORD]}"));;
+            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
 }
 
-- 
1.9.1

_______________________________________________
meta-arago mailing list
meta-arago@arago-project.org
http://arago-project.org/cgi-bin/mailman/listinfo/meta-arago

Reply via email to