Add wol(1) completion.
May need a bit of work, see failing test case ("wol 00:").
This commit is contained in:
parent
d270695374
commit
310eb69245
3
CHANGES
3
CHANGES
@ -32,7 +32,8 @@ bash-completion (2.x)
|
|||||||
general hostname completions.
|
general hostname completions.
|
||||||
* Add abook and wtf completion, based on work by Raphaël Droz.
|
* Add abook and wtf completion, based on work by Raphaël Droz.
|
||||||
* Add cvsps, dragon, fusermount, jarsigner, k3b, lftpget, pm-utils, rtcwake,
|
* 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
|
* Don't overwrite other host completions when completing from multiple
|
||||||
SSH known hosts files.
|
SSH known hosts files.
|
||||||
* Speed up installed rpm package completion on SUSE, based on work by
|
* Speed up installed rpm package completion on SUSE, based on work by
|
||||||
|
@ -682,6 +682,25 @@ _signals()
|
|||||||
done
|
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
|
# This function completes on configured network interfaces
|
||||||
#
|
#
|
||||||
_configured_interfaces()
|
_configured_interfaces()
|
||||||
|
47
contrib/wol
Normal file
47
contrib/wol
Normal file
@ -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
|
1
test/completion/wol.exp
Normal file
1
test/completion/wol.exp
Normal file
@ -0,0 +1 @@
|
|||||||
|
assert_source_completions wol
|
16
test/fixtures/shared/bin/arp
vendored
Executable file
16
test/fixtures/shared/bin/arp
vendored
Executable file
@ -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
|
24
test/fixtures/shared/bin/ifconfig
vendored
Executable file
24
test/fixtures/shared/bin/ifconfig
vendored
Executable file
@ -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
|
32
test/lib/completions/wol.exp
Normal file
32
test/lib/completions/wol.exp
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user