c133f41833ba1ce6a3868a644ad29caa17bfa75a

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merge pull request #343 from giddie/plugin-wakeonlan

Plugin to make WOL nice & easy

Diff

 1diff --git a/plugins/wakeonlan/README b/plugins/wakeonlan/README
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..16fdd4587060ce16895373d3bd5e9713113994c3
 4--- /dev/null
 5+++ b/plugins/wakeonlan/README
 6@@ -0,0 +1,29 @@
 7+This plugin provides a wrapper around the "wakeonlan" tool available from most
 8+distributions' package repositories, or from the following website:
 9+
10+http://gsd.di.uminho.pt/jpo/software/wakeonlan/
11+
12+In order to use this wrapper, create the ~/.wakeonlan directory, and place in
13+that directory one file for each device you would like to be able to wake. Give
14+the file a name that describes the device, such as its hostname. Each file
15+should contain a line with the mac address of the target device and the network
16+broadcast address.
17+
18+For instance, there might be a file ~/.wakeonlan/leto with the following
19+contents:
20+
21+00:11:22:33:44:55:66 192.168.0.255
22+
23+To wake that device, use the following command:
24+
25+# wake leto
26+
27+The available device names will be autocompleted, so:
28+
29+# wake <tab>
30+
31+...will suggest "leto", along with any other configuration files that were
32+placed in the ~/.wakeonlan directory.
33+
34+For more information regarding the configuration file format, check the
35+wakeonlan man page.
36diff --git a/plugins/wakeonlan/_wake b/plugins/wakeonlan/_wake
37new file mode 100644
38index 0000000000000000000000000000000000000000..4ab10d374a6e5d82d953d3d32b5f2ade2ec9ddd6
39--- /dev/null
40+++ b/plugins/wakeonlan/_wake
41@@ -0,0 +1,4 @@
42+#compdef wake
43+#autoload
44+
45+_arguments "1:device to wake:_files -W '$HOME/.wakeonlan'" && return 0
46diff --git a/plugins/wakeonlan/wakeonlan.plugin.zsh b/plugins/wakeonlan/wakeonlan.plugin.zsh
47new file mode 100644
48index 0000000000000000000000000000000000000000..6cef7d44ad72f59690093b6e13cdd95d629cff69
49--- /dev/null
50+++ b/plugins/wakeonlan/wakeonlan.plugin.zsh
51@@ -0,0 +1,14 @@
52+function wake() {
53+  local config_file="$HOME/.wakeonlan/$1"
54+  if [[ ! -f "$config_file" ]]; then
55+    echo "ERROR: There is no configuration file at \"$config_file\"."
56+    return 1
57+  fi
58+
59+  if (( ! $+commands[wakeonlan] )); then
60+    echo "ERROR: Can't find \"wakeonlan\".  Are you sure it's installed?"
61+    return 1
62+  fi
63+
64+  wakeonlan -f "$config_file"
65+}