Created
August 14, 2015 22:29
-
-
Save stecman/0b450e92414a763752ba to your computer and use it in GitHub Desktop.
Beam shell helpers
This file contains 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
# Helper shell functions and completions for use with Beam | |
# https://github.com/heyday/beam | |
# Print the .beamlog file for a beam target. | |
# Target defaults to live if not given | |
# | |
# usage: whatsup [target] | |
# | |
function whatsup() { | |
local server="${1-live}"; | |
>&2 echo "Getting beamlog for $server.."; | |
beam down $server -p .beamlog -q --no-prompt && \ | |
(cat .beamlog && \ | |
rm .beamlog) \ | |
|| echo "Failed: either '$server' is not a valid target or you're not in a project directory" | |
} | |
# Bash completion for functions that accept beam targets | |
function _list_beam_targets() | |
{ | |
local RESULT cur; | |
cur=${COMP_WORDS[COMP_CWORD]} | |
RESULT=`php -r ' | |
$path = getcwd(); | |
do { | |
if (is_file("$path/beam.json")) { | |
$json = json_decode(file_get_contents("$path/beam.json"), true); | |
echo implode("\n", array_keys($json["servers"])); | |
} | |
} while(($path = dirname($path)) != "/"); | |
';` | |
COMPREPLY=( $(compgen -W "$RESULT" -- $cur) ); | |
} | |
complete -F _list_beam_targets whatsup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment