Skip to content

Instantly share code, notes, and snippets.

@grasmash
Last active November 10, 2021 14:39
Show Gist options
  • Save grasmash/e1ae07b93dd3390b90a19c2cf122c028 to your computer and use it in GitHub Desktop.
Save grasmash/e1ae07b93dd3390b90a19c2cf122c028 to your computer and use it in GitHub Desktop.
001-acquia-list-ides.1h.php
<?php
require $_SERVER['HOME'] . "/.composer/vendor/autoload.php";
const ACLI_PATH = '/usr/local/bin/acli';
const DEBUG_MODE = false;
/**
* Validates that ACLI, Composer, and steveedson/bitbar-php are installed.
*
* Returns early with error message if pre-requisite is not installed.
*/
function checkPrerequisites() {
if (!file_exists('/usr/local/bin/acli')) {
print "Error\n";
print "---\n";
print "Missing pre-requisite Acquia CLI\n";
print "Read Install Instructions|color=red|href=https://gist.github.com/grasmash/e1ae07b93dd3390b90a19c2cf122c028#file-install-md";
exit(0);
}
if (!file_exists($_SERVER['HOME'] . '/.composer/vendor/autoload.php')) {
print "Error\n";
print "---\n";
print "Missing pre-requisite Composer\n";
print "Read Install Instructions|color=red|href=https://gist.github.com/grasmash/e1ae07b93dd3390b90a19c2cf122c028#file-install-md";
exit(0);
}
if (!file_exists($_SERVER['HOME'] . '/.composer/vendor/steveedson/bitbar-php')) {
print "Error\n";
print "---\n";
print "Missing pre-requisite steveedson/bitbar-php\n";
print "Read Install Instructions|color=red|href=https://gist.github.com/grasmash/e1ae07b93dd3390b90a19c2cf122c028#file-install-md";
exit(0);
}
}
/**
* Run an acli command.
*
* @return object
* A decoded JSON response.
*/
function acli($command)
{
$extras = ' --no-interaction';
$command = ACLI_PATH . " {$command}{$extras}";
$output = passthrough_return($command);
return json_decode($output);
}
/**
* Executes a command via passthru. Grabs output.
*
* @return string
* The command output.
*/
function passthrough_return($command)
{
ob_start();
if (!DEBUG_MODE) {
$command = $command . ' 2>/dev/null';
}
passthru($command);
$output = ob_get_clean();
if (DEBUG_MODE) {
echo "----- DEBUG [$command] -----\n";
echo "OUTPUT:\n";
var_dump($output);
echo "\n";
}
return $output;
}

Install Acquia Cloud plugins

  1. Install the pre-requisites:
    1. Composer
    2. BitBar PHP
      composer global require steveedson/bitbar-php
      
    3. Acquia CLI
      curl -OL https://github.com/acquia/cli/releases/latest/download/acli.phar
      chmod +x acli.phar
      mv acli.phar /usr/local/bin/acli
      
    4. Authenticate with Acquia CLI:
      acli login
      
  2. Install xbar from https://xbarapp.com/.
  3. Download this Gist and copy the contents into your ~/Library/Application Support/xbar directory.
    mkdir -p ~/Library/Application\ Support/xbar/plugins
    curl -L https://gist.github.com/grasmash/e1ae07b93dd3390b90a19c2cf122c028/archive/38956395282efe3a2a94c083b91bd057b3105e01.zip > acquia-xbar.zip
    unzip -j acquia-xbar.zip -d ~/Library/Application\ Support/xbar/plugins
    
  4. Enable the plugins via the xBar UI.

That's it!

#!/usr/bin/php
<?php
# <xbar.title>Acquia Cloud Applications</xbar.title>
# <xbar.version>v1.0</xbar.version>
# <xbar.author>Matthew Grasmick</xbar.author>
# <xbar.author.github>grasmash</xbar.author.github>
# <xbar.desc>List Acquia Cloud Applications.</xbar.desc>
# <xbar.dependencies>php,acli,composer,steveedson/bitbar-php</xbar.dependencies>
// @see https://github.com/matryer/xbar-plugins/blob/main/CONTRIBUTING.md
require __DIR__ . '/.acquia-includes.php';
use SteveEdson\BitBar;
checkPrerequisites();
// Create BitBar formatter
// @see https://github.com/SteveEdson/bitbar-php
$bb = new BitBar();
$line = $bb->newLine();
$mainMenu = $line
->setText('Acquia Apps')
->show(TRUE);
$apps = acli("api:applications:list --sort=name");
if (!is_array($apps)) {
$mainMenu = $line
->setColor('red')
->setText('Could not get application list. Did you authenticate using Acquia CLI?')
->show();
exit(0);
}
$mainMenu = $line
->setText('Visit Acquia Cloud')
->setUrl('https://cloud.acquia.com/a')
->show(FALSE);
$mainMenu = $line
->setText('My Account')
->setUrl('https://accounts.acquia.com/account')
->show(TRUE);
foreach ($apps as $app) {
$mainMenu = $line
->setText($app->name)
->setUrl('https://cloud.acquia.com/a/applications/' . $app->uuid);
$mainMenu = $mainMenu->addSubMenu()
->newLine()
->setUrl('https://cloud.acquia.com/a/applications/' . $app->uuid . '/environments')
->setText('View environments');
$mainMenu = $mainMenu->addSubMenu()
->newLine()
->setUrl('https://cloud.acquia.com/api/applications/' . $app->uuid)
->setText('View API response');
$mainMenu->show();
}
exit(0);
#!/usr/bin/php
<?php
# <xbar.title>Acquia Cloud IDEs</xbar.title>
# <xbar.version>v1.0</xbar.version>
# <xbar.author>Matthew Grasmick</xbar.author>
# <xbar.author.github>grasmash</xbar.author.github>
# <xbar.desc>List Acquia Cloud IDEs.</xbar.desc>
# <xbar.dependencies>php,acli,composer,steveedson/bitbar-php</xbar.dependencies>
// @see https://github.com/matryer/xbar-plugins/blob/main/CONTRIBUTING.md
require __DIR__ . '/.acquia-includes.php';
use SteveEdson\BitBar;
checkPrerequisites();
// Create BitBar formatter
// @see https://github.com/SteveEdson/bitbar-php
$bb = new BitBar();
$line = $bb->newLine();
$mainMenu = $line
->setText('Acquia IDEs')
->show(TRUE);
$ides = acli("api:accounts:ide-list");
if (!is_array($ides)) {
$mainMenu = $line
->setColor('red')
->setText('Could not get IDE list. Did you authenticate using Acquia CLI?')
->show();
exit(0);
}
$mainMenu = $line
->setText('Visit Acquia Cloud')
->setUrl('https://cloud.acquia.com/a')
->show(FALSE);
$mainMenu = $line
->setText('My Account')
->setUrl('https://accounts.acquia.com/account')
->show(TRUE);
foreach ($ides as $ide) {
// Set the text and formatting
$mainMenu = $line
->setText($ide->label);
$mainMenu = $mainMenu->addSubMenu()
->newLine()
->setUrl($ide->_links->ide->href)
->setText('Open IDE');
$mainMenu = $mainMenu->addSubMenu()
->newLine()
->setUrl($ide->_links->web->href)
->setText("Open IDE's Drupal site");
$mainMenu = $mainMenu->addSubMenu()
->newLine()
->setUrl(str_replace('/api', '/a', $ide->_links->application->href))
->setText('Visit parent Cloud app');
$mainMenu = $mainMenu->addSubMenu()
->newLine()
->setUrl($ide->_links->self->href)
->setText("View IDE API endpoint");
$mainMenu = $mainMenu->addSubMenu()
->newLine()
->setBash(ACLI_PATH,['ide:delete' , $ide->uuid, '--no-interaction'])
->setTerminal(TRUE)
->setColor('red')
->setText('Delete IDE');
$mainMenu->show();
}
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment