9

I wish to place a shell script in my gem's bin dir, along with other Ruby programs that belong to the package. I wish to have this shell script installed in the bin directory as-is (that is, no wrappers). Is that possible with Ruby gems at all? I would be happy with post-install hooks if not otherwise possible. Anybody has any experience with this?

3
  • 1
    What have you tried? That should work as far as I know. A wrapper might be applied, but it shouldn't be a big issue. That's mostly so things like bundle exec will work correctly. Commented May 16, 2014 at 18:19
  • 1
    Unfortunately, that is an issue. The wrapper is a ruby script which attempts to load my shell script and execute it as a Ruby program. It obviously barfs when encountering bash syntax. Commented Jul 10, 2014 at 12:33
  • If you're writing a Ruby gem, you need to stick to the conventions it imposes. One of them is the expectation that your scripts will be compatible with the version of Ruby the user has selected. If you need to run a shell script, you can always use exec to convert your Ruby process into a bash script with the same arguments. Commented Jul 10, 2014 at 14:48

1 Answer 1

8

This issue is described here: https://github.com/rubygems/rubygems/issues/88

If the gem you're developing is intended only for your own use, you can simply install it with

gem install --no-wrapper my_gem 

I think you'd best write a ruby script which runs your bash script. Here's an example on how to do that:


bin/test_gem

#!/usr/bin/env ruby bin_dir = File.expand_path(File.dirname(__FILE__)) shell_script_path = File.join(bin_dir, 'test_gem.sh') `#{shell_script_path}` 

bin/test_gem.sh

#!/bin/sh echo "Hello World!" 

test_gem.gemspec

spec.files = [ # ... 'bin/test_gem', 'bin/test_gem.sh' ] # ... spec.executables = ['test_gem'] 

NOTE: Don't forget to set both files in the bin folder to executable!

Note that while test_gem.sh is registered with the files Rubygems command, it's not registered as executables: it will just be placed in the installed gem's dir but not wrapped/shimmed.

If you install your gem (and run rbenv rehash if necessary), calling test_gem will result in the ruby script executing your shell script.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.