Skip to content

Instantly share code, notes, and snippets.

@eloyesp
Forked from rstacruz/rbenv-sync-binstubs
Last active August 29, 2015 14:07
Show Gist options
  • Save eloyesp/1abf6a758babca9112d5 to your computer and use it in GitHub Desktop.
Save eloyesp/1abf6a758babca9112d5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# Syncs Ruby binstubs for ruby-communal-gems.
# Run this everytime you install a new Ruby, or when you install a new gem
# with a bin/ command. (ie, when you typically do rbenv rehash)
#
# See: https://github.com/tpope/rbenv-communal-gems/issues/5
#
require 'fileutils'
versions_path = File.expand_path('~/.rbenv/versions')
prefixes = %w[2.0.0-* 2.1.* 1.9.*]
debug = ARGV.include?('-d') || ARGV.include?('--debug')
puts "(running in simulation mode)" if debug
prefixes.each do |prefix|
# { 'pry' => '/path/to/pry', ... }
bins = Dir["#{versions_path}/#{prefix}/bin/*"].inject({}) do |hash, bin|
base = File.basename(bin)
hash[base] = bin unless %w[gem ruby irb ri rdoc erb testrb].include?(base)
hash
end
Dir["#{versions_path}/#{prefix}"].each do |ver|
bins.each do |bin, path|
target = ver+'/bin/'+bin
unless File.exists?(target)
puts '+ '+target
FileUtils.cp path, target unless debug
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment