Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
57 changes: 57 additions & 0 deletions plugins/wake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# wakeonlan

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:

```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:

```bash
wake server
```

The available device names will be autocompleted, so:

```bash
wake <tab>
```

...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:
```
Usage: wake <device>
Available devices: server
```

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:

```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!
44 changes: 44 additions & 0 deletions plugins/wake/wake.plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/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 @ commit 1d9eacb34f59f3bf82a9de0d7b474cb4c501e3fd

function wake() {
local cfgdir="$HOME/.wakeonlan"
local cfgfile="$cfgdir/$1"

if [[ -z "$1" || ! -f "$cfgfile" ]]; then
_omb_util_print "Usage: wake <device>"
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 ! _omb_util_command_exists wakeonlan; then
_omb_util_print "ERROR: 'wakeonlan' not found. Install it (https://github.com/jpoliv/wakeonlan)." >&2
return 1
fi

local IFS=$' \t\n'
local mac bcast
read -r mac bcast < "$cfgfile"

if [[ -z "$mac" || -z "$bcast" ]]; then
_omb_util_print "ERROR: Invalid config format in '$cfgfile'. Expected: <MAC> <broadcast-IP>" >&2
return 1
fi

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") )
}
complete -F _wake_completion wake