Giter VIP home page Giter VIP logo

Comments (21)

taylorzane avatar taylorzane commented on May 13, 2024 6

@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.

jakeonrails avatar jakeonrails commented on May 13, 2024 6

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.

kylesezhi avatar kylesezhi commented on May 13, 2024 3

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.

jrnewell avatar jrnewell commented on May 13, 2024 1

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.

ripienaar avatar ripienaar commented on May 13, 2024

It works fine, example @ https://github.com/ripienaar/sensu_bitbar

Generally "It does not work" isn't a useful error report.

from xbar.

luke3butler avatar luke3butler commented on May 13, 2024

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.

uri avatar uri commented on May 13, 2024

Did you make sure to add the correct shebang and make your script executable?

from xbar.

luke3butler avatar luke3butler commented on May 13, 2024

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.

jefvlamings avatar jefvlamings commented on May 13, 2024

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:
schermafbeelding 2016-01-06 om 09 39 10

Any ideas on how to solve this issue?

from xbar.

matryer avatar matryer commented on May 13, 2024

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.

asnodgrass avatar asnodgrass commented on May 13, 2024

@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.

asnodgrass avatar asnodgrass commented on May 13, 2024

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.

luke3butler avatar luke3butler commented on May 13, 2024

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.

asnodgrass avatar asnodgrass commented on May 13, 2024

@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.

estiens avatar estiens commented on May 13, 2024

Yes, would be great to be able to use rbenv or rvm without using a wrapper script!

from xbar.

estiens avatar estiens commented on May 13, 2024

@taylorzane awesome, that works perfectly for me! 💯

from xbar.

bbugh avatar bbugh commented on May 13, 2024

There doesn't yet seem to be a way to do this with RVM without a wrapper script.

from xbar.

vogonistic avatar vogonistic commented on May 13, 2024

Maybe something similar to this can be implemented, to get a good user configured environment: atom/atom#11054

from xbar.

MatzFan avatar MatzFan commented on May 13, 2024

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.

JRiggles avatar JRiggles commented on May 13, 2024

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.

ChrisZou avatar ChrisZou commented on May 13, 2024

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"

You may need to make your script executable

from xbar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.