Revise rbenv rakefile

This commit is contained in:
Henrik Lissner 2014-12-13 19:33:21 -05:00
parent c97c785dd5
commit f08ef51191
2 changed files with 35 additions and 33 deletions

View file

@ -1,11 +1,12 @@
RBENV_ROOT = File.expand_path("~/.rbenv") RBENV_ROOT = File.expand_path('~/.rbenv')
def rbenv_installed? def rbenv_installed?
Dir.exists?(RBENV_ROOT) Dir.exist?(RBENV_ROOT)
end end
def rbenv_versions def rbenv_versions
`ls -1 #{RBENV_ROOT}/versions`.split("\n") if Dir.exists? "#{RBENV_ROOT}/versions" return [] unless Dir.exist? "#{RBENV_ROOT}/versions"
`ls -1 #{RBENV_ROOT}/versions`.split("\n")
end end
def rbenv_plugins def rbenv_plugins
@ -14,7 +15,6 @@ end
def rbenv_set_default_gems(*gems) def rbenv_set_default_gems(*gems)
default_gems_file = "#{RBENV_ROOT}/default-gems" default_gems_file = "#{RBENV_ROOT}/default-gems"
return if !gems.is_a?(Array) or gems.length == 0 or File.exists?(default_gems_file)
File.write(default_gems_file, gems.join("\n")) File.write(default_gems_file, gems.join("\n"))
end end
@ -24,31 +24,31 @@ end
### ###
desc "Install/update rbenv & all rubies" desc 'Install/update rbenv & all rubies'
task :rbenv => 'rbenv:update' task rbenv: 'rbenv:update'
namespace :rbenv do namespace :rbenv do
task :install do task :install do
unless rbenv_installed? unless rbenv_installed?
echo "Installing rbenv" echo 'Installing rbenv'
github "sstephenson/rbenv", RBENV_ROOT github 'sstephenson/rbenv', RBENV_ROOT
mkdir_p "#{RBENV_ROOT}/plugins" mkdir_p "#{RBENV_ROOT}/plugins"
[ "sstephenson/rbenv-vars", ['sstephenson/rbenv-vars',
"sstephenson/ruby-build", 'sstephenson/ruby-build',
"sstephenson/rbenv-default-gems", 'sstephenson/rbenv-default-gems',
"sstephenson/rbenv-gem-rehash", 'sstephenson/rbenv-gem-rehash',
"fesplugas/rbenv-installer", 'fesplugas/rbenv-installer',
"fesplugas/rbenv-bootstrap", 'fesplugas/rbenv-bootstrap',
"rkh/rbenv-update", 'rkh/rbenv-update',
"rkh/rbenv-whatis", 'rkh/rbenv-whatis',
"rkh/rbenv-use" 'rkh/rbenv-use'
].each do |pkg| ].each do |pkg|
echo "Installing #{pkg}", 2 echo "Installing #{pkg}", 2
github pkg, "#{RBENV_ROOT}/plugins/#{pkg.split("/")[1]}" github pkg, "#{RBENV_ROOT}/plugins/#{pkg.split('/')[1]}"
end end
echo "Initializing rbenv", 2 echo 'Initializing rbenv', 2
sh_safe "eval \"$(#{RBENV_ROOT}/bin/rbenv init -)\"" sh_safe "eval \"$(#{RBENV_ROOT}/bin/rbenv init -)\""
end end
@ -56,18 +56,18 @@ namespace :rbenv do
rbenv_set_default_gems( rbenv_set_default_gems(
'bundler', 'bundler',
'rspec', 'rspec',
'doing',
'pry', 'pry',
'pry-doc', 'pry-doc',
'factory_girl', 'pry-byebug',
'guard', 'pry-rescue',
'rb-fsevent', 'pry-stack_explorer',
'guard-livereload', 'ripper-tags',
'guard-sass', 'gem-ripper-tags'
'guard-concat'
) )
# Install global ruby + gems # Install global ruby + gems
ruby_version = "2.1.2" ruby_version = '2.1.3'
unless rbenv_version_installed? ruby_version unless rbenv_version_installed? ruby_version
echo "Setting up default ruby (#{ruby_version})", 2 echo "Setting up default ruby (#{ruby_version})", 2
sh_safe "rbenv install #{ruby_version}" sh_safe "rbenv install #{ruby_version}"
@ -76,27 +76,27 @@ namespace :rbenv do
end end
end end
task :update => "rbenv:install" do task update: 'rbenv:install' do
echo "Updating rbenv & plugins" echo 'Updating rbenv & plugins'
sh_safe "rbenv update" sh_safe 'rbenv update'
rbenv_versions.each do |version| rbenv_versions.each do |version|
echo "Updating ruby #{version}" echo "Updating ruby #{version}"
cmd = "#{RBENV_ROOT}/shims/gem" cmd = "#{RBENV_ROOT}/shims/gem"
cmd = "sudo #{cmd}" if version == "system" cmd = "sudo #{cmd}" if version == 'system'
sh_safe "RBENV_VERSION=#{version} #{cmd} update --system -f" sh_safe "RBENV_VERSION=#{version} #{cmd} update --system -f"
sh_safe "RBENV_VERSION=#{version} #{cmd} update -f" sh_safe "RBENV_VERSION=#{version} #{cmd} update -f"
sh_safe "RBENV_VERSION=#{version} #{cmd} clean" sh_safe "RBENV_VERSION=#{version} #{cmd} clean"
end end
sh_safe "rbenv rehash" sh_safe 'rbenv rehash'
end end
if rbenv_installed? if rbenv_installed?
task :remove do task :remove do
echo "Deleting rbenv" echo 'Deleting rbenv'
sh_safe "rm -rf #{RBENV_ROOT}" sh_safe "rm -rf #{RBENV_ROOT}"
end end
end end

4
zshrc
View file

@ -14,7 +14,9 @@ source ~/.zsh/aliases
# Initialize rbenv and pyenv; rehashing slows down zsh startup, so we # Initialize rbenv and pyenv; rehashing slows down zsh startup, so we
# disable it. # disable it.
is-callable 'rbenv' && eval "$(rbenv init - --no-rehash)" if is-callable 'rbenv'; then
eval "$(rbenv init - --no-rehash)"
fi
if is-callable 'pyenv'; then if is-callable 'pyenv'; then
eval "$(pyenv init - --no-rehash)" eval "$(pyenv init - --no-rehash)"
eval "$(pyenv virtualenv-init -)" eval "$(pyenv virtualenv-init -)"