In the plugin section of the readme.md it says 'To write a plugin, just write some form of executable script that outputs to the standard output' but it doesn't seem to work for python or ruby with me.
Also the 'memusage.5s.py' plugin under Systems doesn't work for me.
Anyone else having trouble with this?
It works fine, example @ https://github.com/ripienaar/sensu_bitbar
Generally "It does not work" isn't a useful error report.
You just need to shebang it for ruby or python.
e.g. #!/usr/bin/env ruby
Using node.js, I needed to export the $PATH as it now mentions in the readme
Did you make sure to add the correct shebang and make your script executable?
Someone asked how I got nodejs working.
file.sh:
#!/bin/bash
scriptpath="/path/to/my/js/script.js"
/usr/local/bin/node $scriptpath;
As an alternative to using a full path to the node executable, you can use
export PATH='your-paths-here'; underneath the shebang
I just typed echo $PATH in terminal to get my PATH.
and then script.js:
console.log("Hello World!");
Apparently my script was throwing errors and because the error wasn't showing anywhere it appeared that it failed to load the script completely.
Anyway, I'm having trouble loading a gem. If I execute my script in terminal in the same directory, it works just fine. When it is being executed in bitbar, one of the gems could not be loaded.
#!/usr/bin/env ruby
puts 'test'
puts '---'
require 'rubygems'
require 'watir-webdriver'
Which gives this as output:

Any ideas on how to solve this issue?
I know the environment inside BitBar is a little different to outside of it. Perhaps you can play around and let me know what you discover?
I was trying to use the wunderground plugin and it fails similarly trying to import a ruby gem. To get it to work properly, I had to first manually source the rbenv environment in a bash script and then call the wunderground ruby script
#!/bin/bash
# to run in rbenv
RBENV=/usr/local/bin/rbenv
eval "$($RBENV init -)"
$HOME/.bitbar/ruby/wunderground.rb $*
exit $?
@jrnewell I use RVM, and also use a wrapper script to execute the plugin:
#!/bin/bash
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
rvm use $PREFERRED_RUBY >/dev/null 2>/dev/null
ruby /path/to/bitbar/plugins/Weather/Wunderground.30m.rb $API_KEY $LOCATION
In my case, I think it may be because I have RVM init in .bash_profile, which is only used for login shells. I'll fiddle with this and let you know what I discover.
The shell environment used for the plugin does not appear to invoke or use any shell init scripts, which eliminates tools like pyenv, rbenv, and rvm from ever being loaded without support in the plugin or a wrapper script.
If you can successfully run something in terminal, then it can be run as a plugin.
As long as the PATH is defined correctly within the script, you should be good.
You can even source your .bash_profile and/or .profile from the script if you wanted.
@luke3butler That's true for pure shell scripts, but it's a bit more complex for other languages when you are not using the system-provided version. In the current state of affairs, a wrapper script (with proper initialization etc) is a necessity for these items.
The solution that worked for me with the Wunderground script: use "which ruby" to find out where ruby is, then copy that to the first line of your script after the shebang.
In my case, it was: #!/usr/local/bin/ruby
Yes, would be great to be able to use rbenv or rvm without using a wrapper script!
@estiens I got rbenv to work without using a wrapper script like so:
#!/usr/bin/env /opt/boxen/rbenv/shims/ruby
puts RUBY_VERSION
I then added a .ruby-version file to my Bitbar plugins folder with the version I wanted to use.
Obviously, you'll have to change the location of the rbenv ruby shim as your environment may be different than mine.
@taylorzane awesome, that works perfectly for me! :100:
There doesn't yet seem to be a way to do this with RVM without a wrapper script.
Maybe something similar to this can be implemented, to get a good user configured environment: https://github.com/atom/atom/pull/11054
For Ruby scripts with a simple output you can always embed them in a shell script & use @asnodgrass's rvm load script like this. Here I needed the socksify gem from my rvm env to be able to do http requests through Tor:
#! /bin/bash
# shellcheck source=/dev/null
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
output=$(
ruby - <<EOF
require 'json'
require 'socksify/http'
uri = URI.parse('http://blockchain.info/ticker')
Net::HTTP.SOCKSProxy('127.0.0.1', 9050).start(uri.host, uri.port) do |http|
puts JSON.parse(http.get(uri.path).body)['GBP']['buy']
end
EOF
)
echo "$output"
I am using this with RVM:
#!/usr/bin/env ruby
# The first time this script runs it will be with system Ruby (gross).
unless ENV['USING_RVM']
# Re-run this script with RVM's default Ruby, after setting up the RVM path,
# and setting USING_RVM to true, so that this sentry code won't run the second
# time through.
system(
<<-EOF
export USING_RVM=true
export PATH="~/.rvm/bin:$PATH"
rvm-auto-ruby #{File.expand_path(__FILE__)}
EOF
)
# Return the exit code from running the script with RVM:
exit $?.exitstatus.to_i
end
# Put the real BitBar plugin code here:
require 'bitbar'
BitBar::Menu.new do
item 'Hello World, from RVM'
end
This works great for any OS X launched Ruby script that doesn't start from a terminal. You can use any gems installed in your default Ruby.
I realize this is both old and closed, but I'm struggling to get @jakeonrails answer to work with Ruby 2.6.5 and RVM. I'm using Fish Shell, which I know has a hard time with Bash...and I can't get any Ruby scripts to work with BitBar.
Sidebar: BitBar isn't working with #!/usr/bin/env ruby either. My test plugin is literally puts 'test' and all I'm getting is "launch path not accessible"
Most helpful comment
I am using this with RVM:
This works great for any OS X launched Ruby script that doesn't start from a terminal. You can use any gems installed in your default Ruby.