xbar
repository·main·Indexed 10 days ago
https://github.com/matryer/xbarA macOS application that displays the output of any script or program directly in the macOS menu bar. It includes a Go package for programmatically loading and executing plugins, a MenuParser for translating xbar items into Wails menus, and tools like sitegen for website generation and xbarmdcheck for plugin metadata validation.
What's inside xbar
- Instead of requiring users to manually edit your script to change settings, you can define Variables in your plugin's metadata. This allows the xbar UI to provide a configuration interface for your users to set values directly.
How xbar stores variable values
mainUser-provided variable values are persisted in a sidecar JSON file located alongside your plugin. The filename follows the pattern
{plugin_name}.vars.json. The keys in the JSON object match the variable names used in the metadata (which are also the environment variable names).// Example: tail.5s.sh.vars.json { "VAR_FILE": "./001-tail.5s.sh", "VAR_LINES": 15 }Locate the xbar plugin directory
mainPlugins are stored in a specific folder on your Mac. If you are migrating from BitBar, move your existing plugins into this directory to install them in xbar.
Plugin Directory Path:
~/Library/Application Support/xbar/pluginsGenerate the xbar website using sitegen
mainThe
sitegentool generates the xbar website by combining plugin data from thematryer/xbar-pluginsGitHub repository with local templates.Prerequisites
Before running the site generator, you should update the CSS in the
xbarapp.comdirectory:cd ../xbarapp.com npm run buildExecution Steps
To build and run the site generator, you must provide a GitHub access token to avoid rate limiting. Use the following command sequence:
go build -o sitegen && XBAR_GITHUB_ACCESS_TOKEN=xxx ./sitegen -small && cd ../../xbarapp.com && npm run buildCLI Options
-small: Processes only a subset of plugins. Remove this flag to process all available plugins.
Important Notes
- GitHub Rate Limiting: Frequent use of this tool may trigger GitHub rate limits. Ensure you use a valid
XBAR_GITHUB_ACCESS_TOKEN.
Build front-end styles
mainCompile and build the front-end styles using the defined npm build script.
npm run buildDeploy the xbarapp.com site to Google App Engine
mainDeploy the application to Google Cloud using the
gcloudCLI. This command targets thexbarappproject and sets the version to6.gcloud app deploy --project xbarapp --version 6Install project dependencies
mainUsenpm installto install the necessary Node.js dependencies for the frontend/sitegen components.npm installAccess variable values as environment variables
mainThe name you define in the
<xbar.var>tag becomes an environment variable available to your plugin script. Note that all environment variable values are treated as strings by the shell/system, even if defined asnumberorbooleanin the metadata.Example usage in a shell script:
# If metadata defines <xbar.var>string(VAR_NAME="World"): Your name.</xbar.var> echo "Hello, ${VAR_NAME}"# <xbar.var>string(VAR_NAME="World"): Your name.</xbar.var> echo "Hello, ${VAR_NAME}"Initial setup and running xbar in development mode
mainIf you are running the project for the first time, you must generate the
.versionfile and install the frontend dependencies before starting the development servers.- Generate version file: Run
git describe --tags > .versioninside theappdirectory. - Install dependencies: Run
npm installinside theapp/frontenddirectory. - Start Frontend: Run
npm run devinside theapp/frontenddirectory. - Start Backend/App: Run
wails devinside theappdirectory.
cd app && git describe --tags > .version cd app/frontend && npm install cd app/frontend && npm run dev cd app && wails dev- Generate version file: Run
Package xbar for release
mainTo package a new release, first tag your current branch with a version number (e.g.,
v0.1.0) and push the tag to your origin. Then, run the./package.shscript.Note: xbar uses
github.com/matryer/gon(a fork ofmitchellh/gon) for code signing.git tag -a v0.1.0 -m "release tag." git push origin v0.1.0 ./package.shUpgrade BitBar plugins to xbar
mainMost BitBar plugins will run in xbar without any changes. To fully leverage xbar features and ensure compatibility, you should update your plugin metadata and parameters.
Recommended updates:
- Replace
<bitbar.*>tags in your metadata with<xbar.*>tags. - Replace the
bashparameter with theshellparameter. - If you were using numbered parameters (e.g.,
param1,param2), note that xbar now supports an unlimited number ofparamNparameters.
- Replace
Run the xbarapp.com site in development mode
mainTo start the development server for the xbarapp.com website, use the
go runcommand on the main entry point.go run main.go