When installing bin stubs, enable --env-shebang if File.dirname(Gem.ruby) is in $PATH
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 4k
- Forks
- 1.9k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 81
Description
Problem
Generating absolute #! for rubygem's bin stubs makes it problematic for ruby switchers such as rbenv and chruby. Whenever a ruby is updated or perhaps moved/named, users must run gem pristin --only-executables to re-generating the gem bin stubs with the new path to the ruby executable.
Proposal
Too accommodate both users of ruby switchers and those who directly invoke ruby (ex: /path/to/ruby -S gem install ...), I propose the following behavior when generating bin stubs for newly installed gems:
-
Check if
File.dirname(Gem.ruby)exists withinENV['PATH'].split(File::PATH_SEPARATOR).a. If so: enable
--env-shebangbehavior by default.
b. If not: use"#!#{Gem.ruby}#{opts}"like normally.
Rationale
If the ruby's bin/ directory exists in $PATH it can be assumed this was intentional and that #!/usr/bin/env ruby would be equivalent to #!/usr/bin/ruby. If the ruby's bin/ directory is not in $PATH, then the user has likely executed it directly by calling /path/to/bin/ruby -S gem install ....
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/rubygems/installer.rb around the referenced bin-stub shebang logic. Trace how Gem.ruby and ENV['PATH'] are used when installing executables, then identify the existing installer coverage to update. Done means PATH detection selects env-style shebangs while direct Ruby paths retain absolute shebangs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100