[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 2.1-10-g9780b0a

Ville Skyttä ville.skytta at iki.fi
Tue Apr 9 15:23:47 UTC 2013


The following commit has been merged in the master branch:
commit cdd2c3d71d9eec2860ad99ba3f81ef65dbd1e723
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Tue Apr 9 18:11:04 2013 +0300

    Revert "nmcli completion was integrated upstream"
    
    This reverts commit 580a4cf6e55ab1afd6b1f8f7efc54436e7046e44.

diff --git a/completions/Makefile.am b/completions/Makefile.am
index d50cc74..4eda2fd 100644
--- a/completions/Makefile.am
+++ b/completions/Makefile.am
@@ -230,6 +230,7 @@ bashcomp_DATA = a2x \
 		newusers \
 		ngrep \
 		nmap \
+		nmcli \
 		nslookup \
 		ntpdate \
 		openssl \
diff --git a/completions/nmcli b/completions/nmcli
new file mode 100644
index 0000000..00628b4
--- /dev/null
+++ b/completions/nmcli
@@ -0,0 +1,199 @@
+# nmcli completion                                           -*- shell-script -*-
+
+_nmcli_list()
+{
+    COMPREPLY=( $( compgen -W '$1' -- "$cur" ) )
+}
+
+_nmcli_con_id()
+{
+    local IFS=$'\n'
+    COMPREPLY=( $( compgen -W "$(nmcli con list 2>/dev/null | \
+        tail -n +2 | awk -F ' {2,}' '{print $1 }')" -- "$cur" ) )
+}
+
+_nmcli_con_uuid()
+{
+    COMPREPLY=( $( compgen -W "$(nmcli con list 2>/dev/null | \
+        tail -n +2 | awk -F ' {2,}' '{print $2}')" -- "$cur" ) )
+}
+
+_nmcli_ap_ssid()
+{
+    local IFS=$'\n'
+    COMPREPLY=( $( compgen -W "$(nmcli dev wifi list 2>/dev/null | \
+        tail -n +2 | awk -F ' {2,}' '{print $1}')" -- "$cur" ) )
+}
+
+_nmcli_ab_bssid()
+{
+    COMPREPLY=( $( compgen -W "$(nmcli dev wifi list 2>/dev/null | \
+        tail -n +2 | awk -F ' {2,}' '{print $2}')" -- "$cur" ) )
+}
+
+_nmcli()
+{
+    local cur prev words cword
+    _init_completion || return
+
+    case $prev in
+        -m|--mode)
+            COMPREPLY=( $( compgen -W 'tabular multiline' -- "$cur" ) )
+            return 0
+            ;;
+        -f|--fields)
+            COMPREPLY=( $( compgen -W 'all common' -- "$cur" ) )
+            return 0
+            ;;
+        -e|--escape)
+            _nmcli_list "yes no"
+            return 0
+            ;;
+        id)
+            _nmcli_con_id
+            return 0
+            ;;
+        uuid)
+            _nmcli_con_uuid
+            return 0
+            ;;
+        iface)
+            _available_interfaces
+            return 0
+            ;;
+        bssid)
+            _nmcli_ab_bssid
+            return 0
+            ;;
+        wep-key-type)
+            _nmcli_list "key phrase"
+            return 0
+            ;;
+    esac
+
+    if [[ $cword -eq 1 ]] ; then
+        if [[ "$cur" == -* ]]; then
+            COMPREPLY=( $( compgen -W '--terse --pretty --mode --fields
+                --escape --version --help' -- "$cur" ) )
+        else
+            COMPREPLY=( $( compgen -W "nm con dev" -- "$cur" ) )
+        fi
+    else
+        local object=${words[1]}
+        local command=${words[2]}
+
+        case $object in
+            nm)
+                case $command in
+                    enable)
+                        _nmcli_list "true false"
+                        return 0
+                        ;;
+                    sleep)
+                        _nmcli_list "true false"
+                        return 0
+                        ;;
+                    wifi)
+                        _nmcli_list "on off"
+                        return 0
+                        ;;
+                    wwan)
+                        _nmcli_list "on off"
+                        return 0
+                        ;;
+                    wimax)
+                        _nmcli_list "on off"
+                        return 0
+                        ;;
+                esac
+
+                COMPREPLY=( $( compgen -W 'status permissions enable sleep
+                    wifi wwan wimax' -- "$cur" ) )
+                ;;
+            con)
+                case $command in
+                    list)
+                        COMPREPLY=( $( compgen -W 'id uuid' -- "$cur" ) )
+                        return 0
+                        ;;
+                    up)
+                        if [[ "$cur" == -* ]]; then
+                            COMPREPLY=( $( compgen -W '--nowait --timeout' \
+                                -- "$cur" ) )
+                        else
+                            COMPREPLY=( $( compgen -W 'id uuid iface ap nsp' \
+                                -- "$cur" ) )
+                        fi
+                        return 0
+                        ;;
+                    down)
+                        COMPREPLY=( $( compgen -W 'id uuid' -- "$cur" ) )
+                        return 0
+                        ;;
+                    delete)
+                        COMPREPLY=( $( compgen -W 'id uuid' -- "$cur" ) )
+                        return 0
+                        ;;
+                esac
+
+                COMPREPLY=( $( compgen -W 'list status up down delete' \
+                        -- "$cur" ) )
+                ;;
+            dev)
+                case $command in
+                    list)
+                        COMPREPLY=( $( compgen -W 'iface' -- "$cur" ) )
+                        return 0
+                        ;;
+                    disconnect)
+                        if [[ "$cur" == -* ]]; then
+                            COMPREPLY=( $( compgen -W '--nowait --timeout' \
+                                -- "$cur" ) )
+                        else
+                            COMPREPLY=( $( compgen -W 'iface' -- "$cur" ) )
+                        fi
+                        return 0
+                        ;;
+                    wifi)
+                        local subcommand=${words[3]}
+
+                        case $subcommand in
+                            list)
+                                COMPREPLY=( $( compgen -W 'iface bssid' \
+                                    -- "$cur" ) )
+                                return 0
+                                ;;
+                            connect)
+                                if [[ "$cur" == -* ]]; then
+                                    COMPREPLY=( $( compgen -W '--private
+                                        --nowait --timeout' -- "$cur" ) )
+                                else
+                                    if [[ "$prev" == "connect" ]]; then
+                                        _nmcli_ap_ssid
+                                    else
+                                        COMPREPLY=( $( compgen -W 'password
+                                            wep-key-type iface bssid name' \
+                                            -- "$cur" ) )
+                                    fi
+                                fi
+                                return 0
+                                ;;
+                        esac
+
+                        COMPREPLY=( $( compgen -W 'list connect' -- "$cur" ) )
+                        return 0
+                        ;;
+                esac
+
+                COMPREPLY=( $( compgen -W 'status list disconnect wifi' \
+                    -- "$cur" ) )
+                ;;
+        esac
+
+    fi
+
+    return 0
+} &&
+complete -F _nmcli nmcli
+
+# ex: ts=4 sw=4 et filetype=sh
diff --git a/completions/postconf b/completions/postconf
index 7425f1e..5b998d9 100644
--- a/completions/postconf
+++ b/completions/postconf
@@ -27,8 +27,13 @@ _postconf()
         return 0
     fi
 
-    COMPREPLY=( $( compgen -W "$( /usr/sbin/postconf | awk '{print $1}' )" -- "$cur" ) )
-
+    local len=${#cur} idx=0 pval
+    for pval in $( /usr/sbin/postconf 2>/dev/null | cut -d ' ' -f 1 ); do
+        if [[ "$cur" == "${pval:0:$len}" ]]; then
+            COMPREPLY[$idx]="$pval$eqext"
+            idx=$(($idx+1))
+        fi
+    done
     return 0
 } &&
 complete -F _postconf postconf
diff --git a/test/completion/nmcli.exp b/test/completion/nmcli.exp
new file mode 100644
index 0000000..816468f
--- /dev/null
+++ b/test/completion/nmcli.exp
@@ -0,0 +1 @@
+assert_source_completions nmcli
diff --git a/test/lib/completions/awk.exp b/test/lib/completions/nmcli.exp
similarity index 80%
copy from test/lib/completions/awk.exp
copy to test/lib/completions/nmcli.exp
index 260dabc..b891f45 100644
--- a/test/lib/completions/awk.exp
+++ b/test/lib/completions/nmcli.exp
@@ -11,9 +11,7 @@ proc teardown {} {
 setup
 
 
-assert_complete_any "awk "
-
-
+assert_complete_any "nmcli "
 sync_after_int
 
 

-- 
bash-completion



More information about the Bash-completion-commits mailing list