diff --git a/CHANGES b/CHANGES index 39e2f37c..791c008d 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 8f8b378d..3f86eaaa 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 00000000..89a1a8ba --- /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 00000000..2e499726 --- /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 00000000..49f42960 --- /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 <