Skip to content

Instantly share code, notes, and snippets.

@stecman
Created August 14, 2015 22:29
Show Gist options
  • Select an option

  • Save stecman/0b450e92414a763752ba to your computer and use it in GitHub Desktop.

Select an option

Save stecman/0b450e92414a763752ba to your computer and use it in GitHub Desktop.
Beam shell helpers
# 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