[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 310eb6924583c9ecc47cabc3221ca030f2294f47

Ville Skyttä ville.skytta at iki.fi
Sun May 9 21:58:27 UTC 2010


The following commit has been merged in the master branch:
commit 310eb6924583c9ecc47cabc3221ca030f2294f47
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Mon May 10 00:54:05 2010 +0300

    Add wol(1) completion.
    
    May need a bit of work, see failing test case ("wol 00:").

diff --git a/CHANGES b/CHANGES
index 39e2f37..791c008 100644
--- a/CHANGES
+++ b/CHANGES
@@ -32,7 +32,8 @@ bash-completion (2.x)
     general hostname completions.
   * Add abook and wtf completion, based on work by Raphaël Droz.
   * Add cvsps, dragon, fusermount, jarsigner, k3b, lftpget, pm-utils, rtcwake,
-    pack200, unpack200, pbzip2, pbunzip2, pbzcat, pigz and unpigz completions.
+    pack200, unpack200, pbzip2, pbunzip2, pbzcat, pigz, unpigz, and wol
+    completions.
   * Don't overwrite other host completions when completing from multiple
     SSH known hosts files.
   * Speed up installed rpm package completion on SUSE, based on work by
diff --git a/bash_completion b/bash_completion
index 8f8b378..3f86eaa 100644
--- a/bash_completion
+++ b/bash_completion
@@ -682,6 +682,25 @@ _signals()
     done
 }
 
+# This function completes on known mac addresses
+#
+_mac_addresses()
+{
+    local re='\([A-Fa-f0-9]\{2\}:\)\{5\}[A-Fa-f0-9]\{2\}'
+    local PATH="$PATH:/sbin:/usr/sbin"
+
+    # Local interfaces (Linux only?)
+    COMPREPLY=( "${COMPREPLY[@]}" $( ifconfig -a 2>/dev/null | sed -ne \
+        "s/.*[[:space:]]HWaddr[[:space:]]\{1,\}\($re\)[[:space:]]*$/\1/p" ) )
+
+    # ARP cache
+    COMPREPLY=( "${COMPREPLY[@]}" $( arp -an 2>/dev/null | sed -ne \
+        "s/.*[[:space:]]\($re\)[[:space:]].*/\1/p" -ne \
+        "s/.*[[:space:]]\($re\)[[:space:]]*$/\1/p" ) )
+
+    COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- "$cur" ) )
+}
+
 # This function completes on configured network interfaces
 #
 _configured_interfaces()
diff --git a/contrib/wol b/contrib/wol
new file mode 100644
index 0000000..89a1a8b
--- /dev/null
+++ b/contrib/wol
@@ -0,0 +1,47 @@
+# wol(1) completion
+
+have wol &&
+_wol()
+{
+    local cur prev split=false
+    COMPREPLY=()
+    _get_comp_words_by_ref -n : cur prev
+    _split_longopt && split=true
+
+    case $prev in
+        -V|--version|--help|-p|--port|--passwd|-w|--wait)
+            return 0
+            ;;
+        -h|--host|-i|--ipaddr)
+            # Broadcast addresses
+            COMPREPLY=( $( PATH=$PATH:/sbin ifconfig -a 2>/dev/null | \
+                sed -ne 's/.*[[:space:]]\{1,\}Bcast:\([^[:space:]]*\).*/\1/p' \
+                    -e 's/.*[[:space:]]\{1,\}broadcast[[:space:]]\{1,\}\([^[:space:]]*\).*/\1/p' ) )
+            _known_hosts_real "$cur"
+            return 0
+            ;;
+        -f|--file)
+            _filedir
+            return 0
+            ;;
+    esac
+
+    $split && return 0
+
+    if [[ "$cur" == -* ]]; then
+        COMPREPLY=( $( compgen -W '--help --version --verbose --wait --host
+            --port --file --passwd' -- "$cur" ) )
+        return 0
+    fi
+
+    _mac_addresses
+} &&
+complete -F _wol wol
+
+# Local variables:
+# mode: shell-script
+# sh-basic-offset: 4
+# sh-indent-comment: t
+# indent-tabs-mode: nil
+# End:
+# ex: ts=4 sw=4 et filetype=sh
diff --git a/test/completion/wol.exp b/test/completion/wol.exp
new file mode 100644
index 0000000..2e49972
--- /dev/null
+++ b/test/completion/wol.exp
@@ -0,0 +1 @@
+assert_source_completions wol
diff --git a/test/fixtures/shared/bin/arp b/test/fixtures/shared/bin/arp
new file mode 100755
index 0000000..49f4296
--- /dev/null
+++ b/test/fixtures/shared/bin/arp
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+# Dummy "arp -an" emulator
+
+# Linux
+echo "? (0.0.0.0) at 00:00:00:00:00:00 [ether] on eth0"
+
+# FreeBSD
+echo "? (0.0.0.0) at 11:11:11:11:11:11 on bge0 expires in 5 seconds [ethernet]"
+
+# Solaris
+cat <<EOF
+Device   IP Address               Mask      Flags      Phys Addr
+------ -------------------- --------------- -------- ---------------
+ce0    0.0.0.0              255.255.255.255 o        22:22:22:22:22:22
+EOF
diff --git a/test/fixtures/shared/bin/ifconfig b/test/fixtures/shared/bin/ifconfig
new file mode 100755
index 0000000..59c9140
--- /dev/null
+++ b/test/fixtures/shared/bin/ifconfig
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+# Dummy "ifconfig -a" emulator
+
+cat <<EOF
+eth0      Link encap:Ethernet  HWaddr 33:33:33:33:33:33
+          inet addr:192.168.80.11  Bcast:192.168.80.255  Mask:255.255.255.0
+          inet6 addr: fe80::000:0000:0000:0000/64 Scope:Link
+          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
+          RX packets:855946 errors:42 dropped:0 overruns:0 frame:42
+          TX packets:477196 errors:0 dropped:0 overruns:0 carrier:0
+          collisions:0 txqueuelen:1000 
+          RX bytes:1142133425 (1.0 GiB)  TX bytes:47621718 (45.4 MiB)
+          Interrupt:23 Base address:0xc000 
+
+lo        Link encap:Local Loopback  
+          inet addr:127.0.0.1  Mask:255.0.0.0
+          inet6 addr: ::1/128 Scope:Host
+          UP LOOPBACK RUNNING  MTU:16436  Metric:1
+          RX packets:129059 errors:0 dropped:0 overruns:0 frame:0
+          TX packets:129059 errors:0 dropped:0 overruns:0 carrier:0
+          collisions:0 txqueuelen:0 
+          RX bytes:7456154 (7.1 MiB)  TX bytes:7456154 (7.1 MiB)
+EOF
diff --git a/test/lib/completions/wol.exp b/test/lib/completions/wol.exp
new file mode 100644
index 0000000..4f93706
--- /dev/null
+++ b/test/lib/completions/wol.exp
@@ -0,0 +1,32 @@
+proc setup {} {
+    # See fixtures/shared/bin/{arp,ifconfig}
+    assert_bash_exec {OLDPATH="$PATH"; PATH="$TESTDIR/fixtures/shared/bin:$PATH";}
+    save_env
+}; # setup()
+
+
+proc teardown {} {
+    assert_env_unmodified
+    assert_bash_exec {PATH="$OLDPATH"; unset -v OLDPATH}
+}; # teardown()
+
+
+setup
+
+
+assert_complete "00:00:00:00:00:00 11:11:11:11:11:11 22:22:22:22:22:22 33:33:33:33:33:33" "wol "
+
+
+sync_after_int
+
+
+# XXX: Why does this fail?  It completes to "00:00:00:00:00:00:00"
+# XXX: (one "00:" too many, apparently added to front).
+# XXX: "wol 00" works as expected.
+assert_complete "00:00:00:00:00:00" "wol 00:"
+
+
+sync_after_int
+
+
+teardown

-- 
bash-completion



More information about the Bash-completion-commits mailing list