Skip to content

Instantly share code, notes, and snippets.

@tentacode
Created April 28, 2016 12:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tentacode/c443c9d571484431756cd7899c811617 to your computer and use it in GitHub Desktop.
Save tentacode/c443c9d571484431756cd7899c811617 to your computer and use it in GitHub Desktop.
Script to execute a command directly in vagrant via `vg bin/somecommand --arg="some argument"`
#!/usr/bin/env php
<?php
$cmd = '';
for ($i = 1; $i < sizeof($argv); $i++) {
$arg = $argv[$i];
if (preg_match('/^(--[^\- =]+=)(.+)$/', $arg, $matches)) {
$arg = sprintf('%s\"%s\"', $matches[1], $matches[2]);
}
$cmd .= ' '.$arg;
}
$cmd = sprintf('vagrant ssh -c "cd /vagrant && %s"', trim($cmd));
system($cmd);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment