X-Git-Url: https://git.rmz.io/dotfiles.git/blobdiff_plain/10cf60790cf2430aba9f7e7120ccd414959e4f81..b55d69396b587288c7e654035190d9e62fa70b71:/zsh/functions/wake diff --git a/zsh/functions/wake b/zsh/functions/wake new file mode 100644 index 0000000..07f4493 --- /dev/null +++ b/zsh/functions/wake @@ -0,0 +1,44 @@ +# This plugin provides a wrapper around the "wakeonlan" tool available from most +# distributions' package repositories, or from the following website: +# +# http://gsd.di.uminho.pt/jpo/software/wakeonlan/ +# +# In order to use this wrapper, create the ~/.wakeonlan directory, and place in +# that directory one file for each device you would like to be able to wake. Give +# the file a name that describes the device, such as its hostname. Each file +# should contain a line with the mac address of the target device and the network +# broadcast address. +# +# For instance, there might be a file ~/.wakeonlan/leto with the following +# contents: +# +# 00:11:22:33:44:55:66 192.168.0.255 +# +# To wake that device, use the following command: +# +# # wake leto +# +# The available device names will be autocompleted, so: +# +# # wake +# +# ...will suggest "leto", along with any other configuration files that were +# placed in the ~/.wakeonlan directory. +# +# For more information regarding the configuration file format, check the +# wakeonlan man page. + +function wake() { + local config_file="$HOME/.wakeonlan/$1" + if [[ ! -f "$config_file" ]]; then + echo "ERROR: There is no configuration file at \"$config_file\"." + return 1 + fi + + if (( ! $+commands[wakeonlan] )); then + echo "ERROR: Can't find \"wakeonlan\". Are you sure it's installed?" + return 1 + fi + + wakeonlan -f "$config_file" +}