Earlier this month I came across BitBar on GitHub. BitBar puts the output from any script in the Mac OS X menu bar. More importantly however, BitBar supports a range of formatting options, turning each script into its own useful utility.
BitBar is powered by plugins, most of these being bash
scripts. While bash scripts can be very versatile and powerful, I personally, can get a lot more done using PHP. I'd rather spend time writing the logic and pulling in data from various sources, than worrying about using the right syntax for BitBar.
Because of this, I've created and open sourced a simple PHP formatter library for BitBar! bitbar-php has support for the majority of the formatting options supported by BitBar, including:
href
to make the dropdown items clickablecolor
to change the text color.font
to change the text font.size
to change the text size.length
to truncate the line to the specified number of characters. A …
will be added to any truncated strings, as well as a tooltip displaying the full string.trim
whether to trim leading/trailing whitespace from the title.Support for bash
, refresh
, dropdown
and terminal
will be added soon.
Currently, BitBar reads any file in your plugins directory as a script and tries to execute it. To workaround this, create a hidden folder beginning with a dot, for example .bitbar/
. In this directory create or edit your composer.json
to include the library:
{
"require": {
"steveedson/bitbar-php": "dev-master"
}
}
or run $ composer require "steveedson/bitbar-php"
#!/usr/bin/php
<?php
require ".bitbar/vendor/autoload.php";
use SteveEdson\BitBar;
// Create BitBar formatter
$bb = new BitBar();
// Create the first line
$line = $bb->newLine();
// Set the text and formatting
$line
->setText("Hello World")
->setColour("yellow")
->setUrl("https://steveedson.co.uk")
->show();
At the time of writing, there isn't a single PHP plugin available on the BitBar website, hopefully this library will help change that.
Need some ideas of what to create? How about the following:
If this project is useful to you, or you think you can help improve it, please star the project on GitHub or submit a pull request.