Comments (21)
@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.
from xbar.
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.
from xbar.
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
from xbar.
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 $?
from xbar.
It works fine, example @ https://github.com/ripienaar/sensu_bitbar
Generally "It does not work" isn't a useful error report.
from xbar.
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
from xbar.
Did you make sure to add the correct shebang and make your script executable?
from xbar.
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!");
from xbar.
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'
Any ideas on how to solve this issue?
from xbar.
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?
from xbar.
@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.
from xbar.
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.
from xbar.
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.
from xbar.
@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.
from xbar.
Yes, would be great to be able to use rbenv or rvm without using a wrapper script!
from xbar.
@taylorzane awesome, that works perfectly for me! 💯
from xbar.
There doesn't yet seem to be a way to do this with RVM without a wrapper script.
from xbar.
Maybe something similar to this can be implemented, to get a good user configured environment: atom/atom#11054
from xbar.
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"
from xbar.
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"
from xbar.
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 literallyputs 'test'
and all I'm getting is "launch path not accessible"
You may need to make your script executable
from xbar.
Related Issues (20)
- Suppress xbar Menu?
- How is the execution of the scripts?
- Crash on load (Sonoma) HOT 11
- auto change to 1 minutes
- Open plugin -> data: -> consumes a lot of processor power
- PyXbar, a python library for menubars that self installs!
- Support image URLs HOT 1
- Bash for loop is not working
- Bash code works on shell but not on Xbar. HOT 1
- Plugin can't call itself HOT 2
- Color of text is washed out if text is not clickable HOT 1
- Is it possible to make an action of main icon?
- Get "https://xbarapp.com/docs/plugins/categories.json": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) HOT 1
- Ellipsis ignores line break HOT 4
- The notation for escaping the pipe for non parameter string
- Refresh does not reflect config changes
- Get "https://xbarapp.com/docs/plugins/categories.json": dial tcp 104.21.77.62:443: connect: connection refused
- Get "https://xbarapp.com/docs/plugins/featured-plugins.json": dial tcp 172.67.204.220:443: connect: connection refused
- Get "https://xbarapp.com/docs/plugins/categories.json": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) HOT 3
- Get "https://xbarapp.com/docs/plugins/featured-plugins.json": dial tcp 172.67.204.220:443: connect: connection refused HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xbar.