-
-
Notifications
You must be signed in to change notification settings - Fork 757
Add wake plugin (WoL wrapper with MAC + broadcast) #703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
h0ek
wants to merge
20
commits into
ohmybash:master
Choose a base branch
from
h0ek:add-wake-plugin
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
102e049
Create wake.plugin.sh
h0ek a0648d4
Create README.md
h0ek 369f905
Update README.md
h0ek 81b4d7b
Update wake.plugin.sh
h0ek f1d05c7
Update README.md
h0ek 0cc425d
Update plugins/wake/README.md
h0ek 3dd7f51
Update plugins/wake/README.md
h0ek e72b0ff
Update README.md
h0ek 941d6b3
Update plugins/wake/README.md
h0ek 50e68ac
Update wake.plugin.sh
h0ek 4b9dc1e
Update wake.plugin.sh
h0ek c676a8e
Update plugins/wake/wake.plugin.sh
h0ek 5266c77
Update wake.plugin.sh
h0ek 24291e8
Update wake.plugin.sh
h0ek 756ae19
style(plugins/wake): fix coding styles
akinomyoga 228f2e5
Update plugins/wake/wake.plugin.sh
h0ek b0498a1
Update plugins/wake/wake.plugin.sh
h0ek a08df15
Update plugins/wake/README.md
h0ek 0c91ba4
Update wake.plugin.sh
h0ek 4a733d2
Update README.md
h0ek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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! | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
h0ek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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 | ||
akinomyoga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _omb_util_print "Available devices: $(_omb_util_list "$cfgdir")" | ||
h0ek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 | ||
h0ek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return 1 | ||
| fi | ||
|
|
||
| local IFS=$' \t\n' | ||
| local mac bcast | ||
| read -r mac bcast < "$cfgfile" | ||
h0ek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if [[ -z "$mac" || -z "$bcast" ]]; then | ||
akinomyoga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _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 | ||
akinomyoga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.