From 102e049ddc1698643a5166f2c40be7555d73587d Mon Sep 17 00:00:00 2001 From: hoek <4890300+h0ek@users.noreply.github.com> Date: Sun, 3 Aug 2025 17:51:57 +0200 Subject: [PATCH 01/20] Create wake.plugin.sh Add wake plugin: WoL wrapper reading MAC and broadcast IP --- plugins/wake/wake.plugin.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 plugins/wake/wake.plugin.sh diff --git a/plugins/wake/wake.plugin.sh b/plugins/wake/wake.plugin.sh new file mode 100644 index 000000000..2af68d4b7 --- /dev/null +++ b/plugins/wake/wake.plugin.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# oh-my-bash.module: wake-on-lan wrapper + autocompletion +# wake.plugin.sh +# Author: hoek from 0ut3r.space +# Based on oh-my-zsh wake plugin + +function wake() { + local cfgdir="$HOME/.wakeonlan" + local cfgfile="$cfgdir/$1" + + if [[ -z "$1" || ! -f "$cfgfile" ]]; then + echo "Usage: wake " + echo "Available devices: $(ls "$cfgdir" | tr '\n' ' ')" + return 1 + fi + + if ! command -v wakeonlan >/dev/null; then + echo "ERROR: 'wakeonlan' not found. Install it (https://github.com/jpoliv/wakeonlan)." >&2 + return 1 + fi + + # Read the two fields: MAC and broadcast-IP + local mac bcast + read -r mac bcast < "$cfgfile" + + # Send magic-packet to the given broadcast address + wakeonlan -i "$bcast" "$mac" +} + +# autocomplete device names from ~/.wakeonlan +_wake_completion() { + local cur="${COMP_WORDS[COMP_CWORD]}" + local cfgdir="$HOME/.wakeonlan" + [[ -d "$cfgdir" ]] || return 0 + COMPREPLY=( $(compgen -W "$(ls "$cfgdir")" -- "$cur") ) +} +complete -F _wake_completion wake From a0648d4ff1af2bba9c8c284271d18d691e8a13ba Mon Sep 17 00:00:00 2001 From: hoek <4890300+h0ek@users.noreply.github.com> Date: Sun, 3 Aug 2025 17:56:33 +0200 Subject: [PATCH 02/20] Create README.md Wake plugin readme. --- plugins/wake/README.md | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 plugins/wake/README.md diff --git a/plugins/wake/README.md b/plugins/wake/README.md new file mode 100644 index 000000000..d8b977693 --- /dev/null +++ b/plugins/wake/README.md @@ -0,0 +1,57 @@ +# wakeonlan + +This plugin provides a wrapper around the "wakeonlan" tool available from most +distributions' package repositories, or from [the following website](https://github.com/jpoliv/wakeonlan). + +To use it, add `wake` to the plugins array in your bashrc file: + +```bash +plugins=(... wake) +``` + +## Usage + +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/server` with the following +contents: + +``` +00:11:22:33:44:55:66 192.168.0.255 +``` + +To wake that device, use the following command: + +```console +wake server +``` + +The available device names will be autocompleted, so: + +```console +wake +``` + +...will suggest "server", along with any other configuration files that were +placed in the `~/.wakeonlan` directory. + +You can also just type `wake` to list show usage and available devices: +``` +Usage: wake +Available devices: server +``` + +For more information regarding the configuration file format, check the +wakeonlan man page. If your distirbution does not offer wakeonlan package just install it manually from the GitHub, here are the steps: + +```bash +curl -RLOJ https://github.com/jpoliv/wakeonlan/raw/refs/heads/master/wakeonlan +chmod a+x wakeonlan +sudo install -o root -g root -m 755 wakeonlan /usr/local/bin/wakeonlan +rm wakeonlan +``` +Enjoy! From 369f905cbe166e6aad5c19509ebae401cab8884c Mon Sep 17 00:00:00 2001 From: hoek <4890300+h0ek@users.noreply.github.com> Date: Sun, 3 Aug 2025 17:58:59 +0200 Subject: [PATCH 03/20] Update README.md Added Wake plugin to the table. --- plugins/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/README.md b/plugins/README.md index e7d1bb042..df691adee 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -55,6 +55,7 @@ By leveraging these plugins, you can streamline your workflow and tackle coding | tmux-autoattach | Plugin related to session management in the tmux terminal multiplexer. | | vagrant | Tool for creating and managing virtual development environments. | | virtualenvwrapper | A set of extensions to the virtualenv tool. | +| wake | This plugin provides a wrapper around the "wakeonlan" tool. | | xterm | Terminal emulator for X Window systems providing a graphical user interface for accessing the command line. | -| zellij-autoattach | Plugin related to session management in the zellij terminal multiplexer. | +| zellij-autoattach | Plugin related to session management in the zellij terminal multiplexer. | | zoxide | Utility for quickly navigating the filesystem based on visited directory history. | From 81b4d7b30f5003a8b0b53e91eba8b83cfd15df5e Mon Sep 17 00:00:00 2001 From: hoek <4890300+h0ek@users.noreply.github.com> Date: Sun, 3 Aug 2025 18:11:23 +0200 Subject: [PATCH 04/20] Update wake.plugin.sh Validate config format and directory before listing. --- plugins/wake/wake.plugin.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/wake/wake.plugin.sh b/plugins/wake/wake.plugin.sh index 2af68d4b7..fd416ec98 100644 --- a/plugins/wake/wake.plugin.sh +++ b/plugins/wake/wake.plugin.sh @@ -10,7 +10,11 @@ function wake() { if [[ -z "$1" || ! -f "$cfgfile" ]]; then echo "Usage: wake " - echo "Available devices: $(ls "$cfgdir" | tr '\n' ' ')" + if [[ -d "$cfgdir" ]]; then + echo "Available devices: $(ls "$cfgdir" | tr '\n' ' ')" + else + echo "No devices configured. Create $cfgdir directory first." + fi return 1 fi @@ -22,6 +26,10 @@ function wake() { # Read the two fields: MAC and broadcast-IP local mac bcast read -r mac bcast < "$cfgfile" + if [[ -z "$mac" || -z "$bcast" ]]; then + echo "ERROR: Invalid config format in '$cfgfile'. Expected: " >&2 + return 1 + fi # Send magic-packet to the given broadcast address wakeonlan -i "$bcast" "$mac" From f1d05c790c601b4a6ebee12201c5f4f5bb33ab0b Mon Sep 17 00:00:00 2001 From: hoek <4890300+h0ek@users.noreply.github.com> Date: Sun, 3 Aug 2025 18:13:48 +0200 Subject: [PATCH 05/20] Update README.md Typo fix. --- plugins/wake/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wake/README.md b/plugins/wake/README.md index d8b977693..413971e33 100644 --- a/plugins/wake/README.md +++ b/plugins/wake/README.md @@ -46,7 +46,7 @@ Available devices: server ``` For more information regarding the configuration file format, check the -wakeonlan man page. If your distirbution does not offer wakeonlan package just install it manually from the GitHub, here are the steps: +wakeonlan man page. If your distribution does not offer wakeonlan package just install it manually from the GitHub, here are the steps: ```bash curl -RLOJ https://github.com/jpoliv/wakeonlan/raw/refs/heads/master/wakeonlan From 0cc425de2d4bb89664b2c935719cd8a67008c434 Mon Sep 17 00:00:00 2001 From: hoek <4890300+h0ek@users.noreply.github.com> Date: Tue, 5 Aug 2025 22:41:51 +0200 Subject: [PATCH 06/20] Update plugins/wake/README.md Co-authored-by: Koichi Murase --- plugins/wake/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wake/README.md b/plugins/wake/README.md index 413971e33..433d09139 100644 --- a/plugins/wake/README.md +++ b/plugins/wake/README.md @@ -39,7 +39,7 @@ wake ...will suggest "server", along with any other configuration files that were placed in the `~/.wakeonlan` directory. -You can also just type `wake` to list show usage and available devices: +You can also just type `wake` to show usage and list available devices: ``` Usage: wake Available devices: server From 3dd7f51a78f3dd484d73735771f74c2fef3e2475 Mon Sep 17 00:00:00 2001 From: hoek <4890300+h0ek@users.noreply.github.com> Date: Tue, 5 Aug 2025 22:43:53 +0200 Subject: [PATCH 07/20] Update plugins/wake/README.md Co-authored-by: Koichi Murase --- plugins/wake/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wake/README.md b/plugins/wake/README.md index 433d09139..63bf92099 100644 --- a/plugins/wake/README.md +++ b/plugins/wake/README.md @@ -1,7 +1,7 @@ # wakeonlan This plugin provides a wrapper around the "wakeonlan" tool available from most -distributions' package repositories, or from [the following website](https://github.com/jpoliv/wakeonlan). +distributions' package repositories, or from [this website](https://github.com/jpoliv/wakeonlan). To use it, add `wake` to the plugins array in your bashrc file: From e72b0ff874922fe658353f91740f7ce8635c1f0e Mon Sep 17 00:00:00 2001 From: hoek <4890300+h0ek@users.noreply.github.com> Date: Tue, 5 Aug 2025 22:45:07 +0200 Subject: [PATCH 08/20] Update README.md --- plugins/wake/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/wake/README.md b/plugins/wake/README.md index 63bf92099..22d00b10e 100644 --- a/plugins/wake/README.md +++ b/plugins/wake/README.md @@ -26,13 +26,13 @@ contents: To wake that device, use the following command: -```console +```bash wake server ``` The available device names will be autocompleted, so: -```console +```bash wake ``` From 941d6b3e7b1f6cb2084c7830f692eb2999377fb8 Mon Sep 17 00:00:00 2001 From: hoek <4890300+h0ek@users.noreply.github.com> Date: Tue, 5 Aug 2025 22:45:49 +0200 Subject: [PATCH 09/20] Update plugins/wake/README.md Co-authored-by: Koichi Murase --- plugins/wake/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wake/README.md b/plugins/wake/README.md index 22d00b10e..0c55d5120 100644 --- a/plugins/wake/README.md +++ b/plugins/wake/README.md @@ -36,7 +36,7 @@ The available device names will be autocompleted, so: wake ``` -...will suggest "server", along with any other configuration files that were +...will suggest "server", along with any other configuration files that are placed in the `~/.wakeonlan` directory. You can also just type `wake` to show usage and list available devices: From 50e68acf3448dcbaca6379a42a1b6f0620401b7a Mon Sep 17 00:00:00 2001 From: hoek <4890300+h0ek@users.noreply.github.com> Date: Tue, 5 Aug 2025 22:58:28 +0200 Subject: [PATCH 10/20] Update wake.plugin.sh --- plugins/wake/wake.plugin.sh | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/plugins/wake/wake.plugin.sh b/plugins/wake/wake.plugin.sh index fd416ec98..fbdec193f 100644 --- a/plugins/wake/wake.plugin.sh +++ b/plugins/wake/wake.plugin.sh @@ -2,40 +2,39 @@ # oh-my-bash.module: wake-on-lan wrapper + autocompletion # wake.plugin.sh # Author: hoek from 0ut3r.space -# Based on oh-my-zsh wake plugin +# Based on oh-my-zsh wake plugin @ commit 1d9eacb34f59f3bf82a9de0d7b474cb4c501e3fd function wake() { local cfgdir="$HOME/.wakeonlan" local cfgfile="$cfgdir/$1" if [[ -z "$1" || ! -f "$cfgfile" ]]; then - echo "Usage: wake " - if [[ -d "$cfgdir" ]]; then - echo "Available devices: $(ls "$cfgdir" | tr '\n' ' ')" - else - echo "No devices configured. Create $cfgdir directory first." - fi + _omb_util_print "Usage: wake " + if [[ -d "$cfgdir" ]]; then + _omb_util_print "Available devices: $(_omb_util_list "$cfgdir")" + else + _omb_util_print "No devices configured. Create $cfgdir directory first." + fi return 1 fi - - if ! command -v wakeonlan >/dev/null; then - echo "ERROR: 'wakeonlan' not found. Install it (https://github.com/jpoliv/wakeonlan)." >&2 + + if ! _omb_util_command_exists wakeonlan; then + _omb_util_print "ERROR: 'wakeonlan' not found. Install it (https://github.com/jpoliv/wakeonlan)." >&2 return 1 fi - # Read the two fields: MAC and broadcast-IP + local IFS=$' \t\n' local mac bcast read -r mac bcast < "$cfgfile" - if [[ -z "$mac" || -z "$bcast" ]]; then - echo "ERROR: Invalid config format in '$cfgfile'. Expected: " >&2 - return 1 - fi - # Send magic-packet to the given broadcast address + if [[ -z "$mac" || -z "$bcast" ]]; then + _omb_util_print "ERROR: Invalid config format in '$cfgfile'. Expected: " >&2 + return 1 + fi + wakeonlan -i "$bcast" "$mac" } -# autocomplete device names from ~/.wakeonlan _wake_completion() { local cur="${COMP_WORDS[COMP_CWORD]}" local cfgdir="$HOME/.wakeonlan" From 4b9dc1ee7444151b607b67b64691082a5743d5a9 Mon Sep 17 00:00:00 2001 From: hoek <4890300+h0ek@users.noreply.github.com> Date: Wed, 6 Aug 2025 12:13:28 +0200 Subject: [PATCH 11/20] Update wake.plugin.sh --- plugins/wake/wake.plugin.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wake/wake.plugin.sh b/plugins/wake/wake.plugin.sh index fbdec193f..bafa6ac12 100644 --- a/plugins/wake/wake.plugin.sh +++ b/plugins/wake/wake.plugin.sh @@ -2,7 +2,7 @@ # oh-my-bash.module: wake-on-lan wrapper + autocompletion # wake.plugin.sh # Author: hoek from 0ut3r.space -# Based on oh-my-zsh wake plugin @ commit 1d9eacb34f59f3bf82a9de0d7b474cb4c501e3fd +# Based on oh-my-zsh wakeonlan plugin @ commit 1d9eacb34f59f3bf82a9de0d7b474cb4c501e3fd function wake() { local cfgdir="$HOME/.wakeonlan" From c676a8e672d4ca10ee49a43ec62705ac29a8d16d Mon Sep 17 00:00:00 2001 From: hoek <4890300+h0ek@users.noreply.github.com> Date: Wed, 6 Aug 2025 12:14:03 +0200 Subject: [PATCH 12/20] Update plugins/wake/wake.plugin.sh Co-authored-by: Koichi Murase --- plugins/wake/wake.plugin.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wake/wake.plugin.sh b/plugins/wake/wake.plugin.sh index bafa6ac12..18902e3b4 100644 --- a/plugins/wake/wake.plugin.sh +++ b/plugins/wake/wake.plugin.sh @@ -19,7 +19,7 @@ function wake() { fi if ! _omb_util_command_exists wakeonlan; then - _omb_util_print "ERROR: 'wakeonlan' not found. Install it (https://github.com/jpoliv/wakeonlan)." >&2 + _omb_util_print "ERROR: 'wakeonlan' not found. Install it from https://github.com/jpoliv/wakeonlan." >&2 return 1 fi From 5266c7761d8e5e2c5ed86d385668c1e8990badc0 Mon Sep 17 00:00:00 2001 From: hoek <4890300+h0ek@users.noreply.github.com> Date: Wed, 6 Aug 2025 12:18:15 +0200 Subject: [PATCH 13/20] Update wake.plugin.sh --- plugins/wake/wake.plugin.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/wake/wake.plugin.sh b/plugins/wake/wake.plugin.sh index 18902e3b4..7eb804142 100644 --- a/plugins/wake/wake.plugin.sh +++ b/plugins/wake/wake.plugin.sh @@ -11,13 +11,16 @@ function wake() { if [[ -z "$1" || ! -f "$cfgfile" ]]; then _omb_util_print "Usage: wake " if [[ -d "$cfgdir" ]]; then - _omb_util_print "Available devices: $(_omb_util_list "$cfgdir")" + # list device files by name + local devices + devices=$(ls "$cfgdir" 2>/dev/null | tr '\n' ' ') + _omb_util_print "Available devices: $devices" else _omb_util_print "No devices configured. Create $cfgdir directory first." fi return 1 fi - + if ! _omb_util_command_exists wakeonlan; then _omb_util_print "ERROR: 'wakeonlan' not found. Install it from https://github.com/jpoliv/wakeonlan." >&2 return 1 From 24291e8fd74c59209c3e4569220e34abf7b64b4d Mon Sep 17 00:00:00 2001 From: hoek <4890300+h0ek@users.noreply.github.com> Date: Wed, 6 Aug 2025 12:20:53 +0200 Subject: [PATCH 14/20] Update wake.plugin.sh --- plugins/wake/wake.plugin.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/wake/wake.plugin.sh b/plugins/wake/wake.plugin.sh index 7eb804142..e0598d939 100644 --- a/plugins/wake/wake.plugin.sh +++ b/plugins/wake/wake.plugin.sh @@ -11,7 +11,6 @@ function wake() { if [[ -z "$1" || ! -f "$cfgfile" ]]; then _omb_util_print "Usage: wake " if [[ -d "$cfgdir" ]]; then - # list device files by name local devices devices=$(ls "$cfgdir" 2>/dev/null | tr '\n' ' ') _omb_util_print "Available devices: $devices" From 756ae190cb517a519c3b1342da09b91fe5b1a8a8 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Wed, 6 Aug 2025 21:43:14 +0900 Subject: [PATCH 15/20] style(plugins/wake): fix coding styles --- plugins/wake/wake.plugin.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/plugins/wake/wake.plugin.sh b/plugins/wake/wake.plugin.sh index e0598d939..7bb3e0418 100644 --- a/plugins/wake/wake.plugin.sh +++ b/plugins/wake/wake.plugin.sh @@ -4,13 +4,13 @@ # Author: hoek from 0ut3r.space # Based on oh-my-zsh wakeonlan plugin @ commit 1d9eacb34f59f3bf82a9de0d7b474cb4c501e3fd -function wake() { - local cfgdir="$HOME/.wakeonlan" - local cfgfile="$cfgdir/$1" +function wake { + local cfgdir=~/.wakeonlan + local cfgfile=$cfgdir/$1 - if [[ -z "$1" || ! -f "$cfgfile" ]]; then - _omb_util_print "Usage: wake " - if [[ -d "$cfgdir" ]]; then + if [[ ! $1 || ! -f $cfgfile ]]; then + _omb_util_print 'Usage: wake ' + if [[ -d $cfgdir ]]; then local devices devices=$(ls "$cfgdir" 2>/dev/null | tr '\n' ' ') _omb_util_print "Available devices: $devices" @@ -29,7 +29,7 @@ function wake() { local mac bcast read -r mac bcast < "$cfgfile" - if [[ -z "$mac" || -z "$bcast" ]]; then + if [[ ! $mac || ! $bcast ]]; then _omb_util_print "ERROR: Invalid config format in '$cfgfile'. Expected: " >&2 return 1 fi @@ -37,10 +37,10 @@ function wake() { wakeonlan -i "$bcast" "$mac" } -_wake_completion() { - local cur="${COMP_WORDS[COMP_CWORD]}" - local cfgdir="$HOME/.wakeonlan" - [[ -d "$cfgdir" ]] || return 0 - COMPREPLY=( $(compgen -W "$(ls "$cfgdir")" -- "$cur") ) +function _omb_plugin_wake_completion { + local cur=${COMP_WORDS[COMP_CWORD]} + local cfgdir=~/.wakeonlan + [[ -d $cfgdir ]] || return 0 + COMPREPLY=($(compgen -W '$(ls "$cfgdir")' -- "$cur")) } -complete -F _wake_completion wake +complete -F _omb_plugin_wake_completion wake From 228f2e5c62668216ce9afe816992dabf08d85600 Mon Sep 17 00:00:00 2001 From: hoek <4890300+h0ek@users.noreply.github.com> Date: Fri, 8 Aug 2025 14:30:11 +0200 Subject: [PATCH 16/20] Update plugins/wake/wake.plugin.sh Co-authored-by: Koichi Murase --- plugins/wake/wake.plugin.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/wake/wake.plugin.sh b/plugins/wake/wake.plugin.sh index 7bb3e0418..fa0e4e504 100644 --- a/plugins/wake/wake.plugin.sh +++ b/plugins/wake/wake.plugin.sh @@ -13,9 +13,9 @@ function wake { if [[ -d $cfgdir ]]; then local devices devices=$(ls "$cfgdir" 2>/dev/null | tr '\n' ' ') - _omb_util_print "Available devices: $devices" + _omb_util_print "Available devices: $devices" >&2 else - _omb_util_print "No devices configured. Create $cfgdir directory first." + _omb_util_print "No devices configured. Create $cfgdir directory first." >&2 fi return 1 fi From b0498a10b67f80da8745c4d7bffa1e80149f9aa1 Mon Sep 17 00:00:00 2001 From: hoek <4890300+h0ek@users.noreply.github.com> Date: Fri, 8 Aug 2025 14:30:26 +0200 Subject: [PATCH 17/20] Update plugins/wake/wake.plugin.sh Co-authored-by: Koichi Murase --- plugins/wake/wake.plugin.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wake/wake.plugin.sh b/plugins/wake/wake.plugin.sh index fa0e4e504..fe9bbca2c 100644 --- a/plugins/wake/wake.plugin.sh +++ b/plugins/wake/wake.plugin.sh @@ -9,7 +9,7 @@ function wake { local cfgfile=$cfgdir/$1 if [[ ! $1 || ! -f $cfgfile ]]; then - _omb_util_print 'Usage: wake ' + _omb_util_print 'Usage: wake ' >&2 if [[ -d $cfgdir ]]; then local devices devices=$(ls "$cfgdir" 2>/dev/null | tr '\n' ' ') From a08df155fdc03bbd36a793ce44f76e46e927774e Mon Sep 17 00:00:00 2001 From: hoek <4890300+h0ek@users.noreply.github.com> Date: Fri, 8 Aug 2025 14:31:01 +0200 Subject: [PATCH 18/20] Update plugins/wake/README.md Co-authored-by: Koichi Murase --- plugins/wake/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wake/README.md b/plugins/wake/README.md index 0c55d5120..d1bed762c 100644 --- a/plugins/wake/README.md +++ b/plugins/wake/README.md @@ -42,7 +42,7 @@ placed in the `~/.wakeonlan` directory. You can also just type `wake` to show usage and list available devices: ``` Usage: wake -Available devices: server +Available devices: server ``` For more information regarding the configuration file format, check the From 0c91ba44b4ba89760f66136d32b1b3e1d7ac38b1 Mon Sep 17 00:00:00 2001 From: hoek <4890300+h0ek@users.noreply.github.com> Date: Fri, 8 Aug 2025 15:14:56 +0200 Subject: [PATCH 19/20] Update wake.plugin.sh Suggestions and additional features implemented. --- plugins/wake/wake.plugin.sh | 123 ++++++++++++++++++++++++++++++------ 1 file changed, 102 insertions(+), 21 deletions(-) diff --git a/plugins/wake/wake.plugin.sh b/plugins/wake/wake.plugin.sh index fe9bbca2c..10b8328a8 100644 --- a/plugins/wake/wake.plugin.sh +++ b/plugins/wake/wake.plugin.sh @@ -3,20 +3,96 @@ # wake.plugin.sh # Author: hoek from 0ut3r.space # Based on oh-my-zsh wakeonlan plugin @ commit 1d9eacb34f59f3bf82a9de0d7b474cb4c501e3fd +# +# Usage: wake [options] +# Options: +# -l, --list list configured devices +# -n, --dry-run show what would be executed (no packet sent) +# -p, --port UDP port (default 9) +# -h, --help usage +# +# Config dir: $HOME/.wakeonlan +# Device file format (either): +# " [broadcast-IP] [port]" +# first non-empty, non-# line +# or key=value lines: +# MAC=aa:bb:cc:dd:ee:ff +# BCAST=192.168.1.255 +# PORT=9 -function wake { - local cfgdir=~/.wakeonlan - local cfgfile=$cfgdir/$1 - - if [[ ! $1 || ! -f $cfgfile ]]; then - _omb_util_print 'Usage: wake ' >&2 - if [[ -d $cfgdir ]]; then - local devices - devices=$(ls "$cfgdir" 2>/dev/null | tr '\n' ' ') - _omb_util_print "Available devices: $devices" >&2 +_wake_cfgdir="$HOME/.wakeonlan" + +_wake_usage() { + _omb_util_print 'Usage: wake [ -l | --list ] [ -n | --dry-run ] [ -p|--port N ] ' >&2 +} +Hyprland +_wake_collect_devices() { + local -n _out=$1 + _out=() + local f + shopt -s nullglob + for f in "$_wake_cfgdir"/*; do + [[ -f $f ]] && _out+=( "$(basename -- "$f")" ) + done + shopt -u nullglob +} + +_wake_read_config() { + local device=$1 cfgfile="$_wake_cfgdir/$device" + local -n _mac=$2 _bcast=$3 _port=$4 + _mac="" _bcast="" _port="" + + local line key val + while IFS= read -r line; do + [[ -z $line || $line =~ ^[[:space:]]*# ]] && continue + if [[ $line == *"="* ]]; then + key=${line%%=*}; val=${line#*=} + key=${key//[[:space:]]/}; val=${val##[[:space:]]} + case "${key^^}" in + MAC) _mac="$val" ;; + BCAST|BROADCAST) _bcast="$val" ;; + PORT) _port="$val" ;; + esac else - _omb_util_print "No devices configured. Create $cfgdir directory first." >&2 + read -r _mac _bcast _port <<<"$line" fi + done <"$cfgfile" + + [[ -n $_mac ]] || return 1 + [[ -n $_bcast ]] || _bcast=255.255.255.255 + [[ -n $_port ]] || _port=9 + return 0 +} + +function wake { + local opt_list=0 opt_dry=0 opt_port="" + local device + + while (($#)); do + case "$1" in + -l|--list) opt_list=1 ;; + -n|--dry-run) opt_dry=1 ;; + -p|--port) shift; opt_port="${1-}" ;; + -h|--help) _wake_usage; return 0 ;; + --) shift; break ;; + -*) _wake_usage; return 2 ;; + *) device="$1"; break ;; + esac + shift + done + + if (( opt_list )); then + local -a devs; _wake_collect_devices devs + ((${#devs[@]})) && printf '%s\n' "${devs[@]}" || _omb_util_print "No devices configured in $_wake_cfgdir" >&2 + return 0 + fi + + local cfgfile="$_wake_cfgdir/${device-}" + if [[ -z ${device-} || ! -f $cfgfile ]]; then + _wake_usage + local -a devs; _wake_collect_devices devs + ((${#devs[@]})) && _omb_util_print "Available devices: ${devs[*]}" >&2 \ + || _omb_util_print "No devices configured. Create $_wake_cfgdir first." >&2 return 1 fi @@ -25,22 +101,27 @@ function wake { return 1 fi - local IFS=$' \t\n' - local mac bcast - read -r mac bcast < "$cfgfile" - - if [[ ! $mac || ! $bcast ]]; then - _omb_util_print "ERROR: Invalid config format in '$cfgfile'. Expected: " >&2 + local mac bcast port + if ! _wake_read_config "$device" mac bcast port; then + _omb_util_print "ERROR: Invalid config in '$cfgfile'. Expected ' [BCAST] [PORT]' or key=value form." >&2 return 1 fi + [[ -n $opt_port ]] && port="$opt_port" + + if (( opt_dry )); then + _omb_util_print "DRY-RUN: wakeonlan -p $port -i $bcast $mac" >&2 + return 0 + fi - wakeonlan -i "$bcast" "$mac" + wakeonlan -p "$port" -i "$bcast" "$mac" } function _omb_plugin_wake_completion { local cur=${COMP_WORDS[COMP_CWORD]} - local cfgdir=~/.wakeonlan - [[ -d $cfgdir ]] || return 0 - COMPREPLY=($(compgen -W '$(ls "$cfgdir")' -- "$cur")) + local -a flags choices + flags=( -l --list -n --dry-run -p --port -h --help ) + [[ -d $_wake_cfgdir ]] && _wake_collect_devices choices || choices=() + local IFS=$'\n' + COMPREPLY=( $(compgen -W "$(printf '%s\n' "${flags[@]}" "${choices[@]}")" -- "$cur") ) } complete -F _omb_plugin_wake_completion wake From 4a733d26644b6ee784fed5f370e9aefe46ce93dd Mon Sep 17 00:00:00 2001 From: hoek <4890300+h0ek@users.noreply.github.com> Date: Fri, 8 Aug 2025 15:15:15 +0200 Subject: [PATCH 20/20] Update README.md Updated readme based on additional features implemented. --- plugins/wake/README.md | 96 ++++++++++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 23 deletions(-) diff --git a/plugins/wake/README.md b/plugins/wake/README.md index d1bed762c..f50c90e7a 100644 --- a/plugins/wake/README.md +++ b/plugins/wake/README.md @@ -1,52 +1,101 @@ -# wakeonlan +# wake -This plugin provides a wrapper around the "wakeonlan" tool available from most +This plugin provides a wrapper around the `wakeonlan` tool available from most distributions' package repositories, or from [this website](https://github.com/jpoliv/wakeonlan). -To use it, add `wake` to the plugins array in your bashrc file: +To use it, add `wake` to the plugins array in your **~/.bashrc**: ```bash plugins=(... wake) ``` -## Usage +## Configuration + +Create the `~/.wakeonlan` directory and place **one file per device** you want to wake. +The filename is the device name (used on the CLI and in completion). + +**Two file formats are supported** (comments and blank lines are ignored): + +**A) Single-line format** +``` + [broadcast-IP] [port] +``` + +**B) key=value format** +``` +MAC=aa:bb:cc:dd:ee:ff +BCAST=192.168.0.255 +PORT=9 +# comments allowed +``` + +**Defaults:** if `BCAST` is omitted → `255.255.255.255`; if `PORT` is omitted → `9`. + +**Example** (`~/.wakeonlan/server`): + +``` +00:11:22:33:44:55 192.168.0.255 9 +``` + +or -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. +``` +MAC=00:11:22:33:44:55 +BCAST=192.168.0.255 +PORT=9 +``` -For instance, there might be a file `~/.wakeonlan/server` with the following -contents: +> Tip: device names can contain spaces, but you’ll need quotes when calling (e.g., `wake "my server"`). + +## Usage ``` -00:11:22:33:44:55:66 192.168.0.255 +wake [options] ``` -To wake that device, use the following command: +### Options +| Option | Description | Default | +|-------------------|---------------------------------------------|---------| +| `-l`, `--list` | List configured device names and exit | — | +| `-n`, `--dry-run` | Show the command that would be executed | — | +| `-p`, `--port N` | Override UDP port | `9` | +| `-h`, `--help` | Show usage | — | + +### Examples + +Wake a device: ```bash wake server ``` -The available device names will be autocompleted, so: - +List devices: ```bash -wake +wake -l ``` -...will suggest "server", along with any other configuration files that are -placed in the `~/.wakeonlan` directory. +Dry-run (don’t send a packet, just show the command): +```bash +wake -n server +# DRY-RUN: wakeonlan -p 9 -i 192.168.0.255 00:11:22:33:44:55 +``` -You can also just type `wake` to show usage and list available devices: +Use a non-default port: +```bash +wake -p 7 server ``` -Usage: wake -Available devices: server + +**Autocompletion:** device names from `~/.wakeonlan` are autocompleted: +```bash +wake ``` -For more information regarding the configuration file format, check the -wakeonlan man page. If your distribution does not offer wakeonlan package just install it manually from the GitHub, here are the steps: +**No-arg behavior:** running `wake` without arguments prints usage and shows available +devices (and exits with code 1). Use `wake -l` for a clean list and exit code 0. + +## Installing `wakeonlan` + +If your distro doesn’t provide `wakeonlan`, install it manually from GitHub: ```bash curl -RLOJ https://github.com/jpoliv/wakeonlan/raw/refs/heads/master/wakeonlan @@ -54,4 +103,5 @@ chmod a+x wakeonlan sudo install -o root -g root -m 755 wakeonlan /usr/local/bin/wakeonlan rm wakeonlan ``` + Enjoy!