2012-01-25 14:13:33 +08:00
|
|
|
require 'rake'
|
2013-03-16 22:47:54 +08:00
|
|
|
require 'fileutils'
|
2013-03-18 01:31:04 +08:00
|
|
|
require File.join(File.dirname(__FILE__), 'bin', 'yadr', 'vundle')
|
2012-01-25 14:13:33 +08:00
|
|
|
|
|
|
|
desc "Hook our dotfiles into system-standard positions."
|
2012-10-10 14:02:36 +08:00
|
|
|
task :install => [:submodule_init, :submodules] do
|
2012-03-23 03:53:25 +08:00
|
|
|
puts
|
|
|
|
puts "======================================================"
|
2012-10-25 23:09:24 +08:00
|
|
|
puts "Welcome to YADR Installation."
|
2012-03-23 03:53:25 +08:00
|
|
|
puts "======================================================"
|
|
|
|
puts
|
2012-09-29 01:38:59 +08:00
|
|
|
|
2012-10-05 02:42:57 +08:00
|
|
|
install_homebrew if RUBY_PLATFORM.downcase.include?("darwin")
|
2012-10-03 13:45:26 +08:00
|
|
|
install_rvm_binstubs
|
2012-09-29 01:38:59 +08:00
|
|
|
|
2012-08-10 02:47:45 +08:00
|
|
|
# this has all the runcoms from this directory.
|
2012-09-27 01:23:39 +08:00
|
|
|
file_operation(Dir.glob('git/*')) if want_to_install?('git configs (color, aliases)')
|
|
|
|
file_operation(Dir.glob('irb/*')) if want_to_install?('irb/pry configs (more colorful)')
|
|
|
|
file_operation(Dir.glob('ruby/*')) if want_to_install?('rubygems config (faster/no docs)')
|
2012-08-10 02:47:45 +08:00
|
|
|
file_operation(Dir.glob('ctags/*')) if want_to_install?('ctags config (better js/ruby support)')
|
2012-11-12 10:15:43 +08:00
|
|
|
file_operation(Dir.glob('tmux/*')) if want_to_install?('tmux config')
|
2012-09-27 01:23:39 +08:00
|
|
|
file_operation(Dir.glob('vimify/*')) if want_to_install?('vimification of command line tools')
|
2013-03-16 22:47:54 +08:00
|
|
|
if want_to_install?('vim configuration (highly recommended)')
|
|
|
|
file_operation(Dir.glob('{vim,vimrc}'))
|
|
|
|
Rake::Task["install_vundle"].execute
|
|
|
|
end
|
2012-01-25 14:13:33 +08:00
|
|
|
|
2012-10-25 22:52:18 +08:00
|
|
|
Rake::Task["install_prezto"].execute
|
2012-01-25 14:13:33 +08:00
|
|
|
|
2012-10-05 02:42:57 +08:00
|
|
|
install_fonts if RUBY_PLATFORM.downcase.include?("darwin")
|
2012-09-29 01:38:59 +08:00
|
|
|
|
2013-03-14 19:56:59 +08:00
|
|
|
install_term_theme if RUBY_PLATFORM.downcase.include?("darwin")
|
|
|
|
|
2012-08-10 02:47:45 +08:00
|
|
|
success_msg("installed")
|
|
|
|
end
|
|
|
|
|
2012-10-25 22:52:18 +08:00
|
|
|
task :install_prezto do
|
|
|
|
if want_to_install?('zsh enhancements & prezto')
|
|
|
|
install_prezto
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-16 22:47:54 +08:00
|
|
|
task :update do
|
|
|
|
Rake::Task["vundle_migration"].execute if needs_migration_to_vundle?
|
2013-03-25 18:25:03 +08:00
|
|
|
Rake::Task["install"].execute
|
2012-10-09 12:38:21 +08:00
|
|
|
#TODO: for now, we do the same as install. But it would be nice
|
|
|
|
#not to clobber zsh files
|
|
|
|
end
|
|
|
|
|
2012-10-10 14:02:36 +08:00
|
|
|
task :submodule_init do
|
2012-10-25 23:09:24 +08:00
|
|
|
unless ENV["SKIP_SUBMODULES"]
|
|
|
|
run %{ git submodule update --init --recursive }
|
|
|
|
end
|
2012-10-10 14:02:36 +08:00
|
|
|
end
|
|
|
|
|
2012-08-10 02:47:45 +08:00
|
|
|
desc "Init and update submodules."
|
|
|
|
task :submodules do
|
2012-10-25 23:09:24 +08:00
|
|
|
unless ENV["SKIP_SUBMODULES"]
|
|
|
|
puts "======================================================"
|
|
|
|
puts "Downloading YADR submodules...please wait"
|
|
|
|
puts "======================================================"
|
|
|
|
|
|
|
|
run %{
|
|
|
|
cd $HOME/.yadr
|
2013-04-02 21:12:24 +08:00
|
|
|
git submodule foreach 'git fetch origin; git checkout master; git reset --hard origin/master; git submodule update --recursive; git clean -df'
|
|
|
|
git clean -df
|
2012-10-25 23:09:24 +08:00
|
|
|
}
|
|
|
|
puts
|
|
|
|
end
|
2012-08-10 02:47:45 +08:00
|
|
|
end
|
|
|
|
|
2013-03-16 22:47:54 +08:00
|
|
|
desc "Performs migration from pathogen to vundle"
|
|
|
|
task :vundle_migration do
|
|
|
|
puts "======================================================"
|
|
|
|
puts "Migrating from pathogen to vundle vim plugin manager. "
|
|
|
|
puts "This will move the old .vim/bundle directory to"
|
|
|
|
puts ".vim/bundle.old and replacing all your vim plugins with"
|
|
|
|
puts "the standard set of plugins. You will then be able to "
|
|
|
|
puts "manage your vim's plugin configuration by editing the "
|
|
|
|
puts "file .vim/vundles.vim"
|
|
|
|
puts "======================================================"
|
|
|
|
|
|
|
|
Dir.glob(File.join('vim', 'bundle','**')) do |sub_path|
|
|
|
|
run %{git config -f #{File.join('.git', 'config')} --remove-section submodule.#{sub_path}}
|
|
|
|
# `git rm --cached #{sub_path}`
|
|
|
|
FileUtils.rm_rf(File.join('.git', 'modules', sub_path))
|
|
|
|
end
|
|
|
|
FileUtils.mv(File.join('vim','bundle'), File.join('vim', 'bundle.old'))
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Runs Vundle installer in a clean vim environment"
|
|
|
|
task :install_vundle do
|
|
|
|
puts "======================================================"
|
|
|
|
puts "Installing vundle."
|
|
|
|
puts "The installer will now proceed to run BundleInstall."
|
|
|
|
puts "Due to a bug, the installer may report some errors"
|
|
|
|
puts "when installing the plugin 'syntastic'. Fortunately"
|
|
|
|
puts "Syntastic will install and work properly despite the"
|
|
|
|
puts "errors so please just ignore them and let's hope for"
|
2013-03-21 22:45:16 +08:00
|
|
|
puts "an update that fixes the problem!"
|
2013-03-16 22:47:54 +08:00
|
|
|
puts "======================================================"
|
|
|
|
|
|
|
|
puts ""
|
|
|
|
|
2013-03-21 05:08:28 +08:00
|
|
|
run %{
|
|
|
|
cd $HOME/.yadr
|
|
|
|
git clone https://github.com/gmarik/vundle.git #{File.join('vim','bundle', 'vundle')}
|
|
|
|
}
|
|
|
|
|
2013-03-18 01:31:04 +08:00
|
|
|
Vundle::update_vundle
|
2013-03-16 22:47:54 +08:00
|
|
|
end
|
|
|
|
|
2012-08-10 02:47:45 +08:00
|
|
|
task :default => 'install'
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
def run(cmd)
|
2012-10-09 12:38:21 +08:00
|
|
|
puts "[Running] #{cmd}"
|
2012-08-10 02:47:45 +08:00
|
|
|
`#{cmd}` unless ENV['DEBUG']
|
|
|
|
end
|
|
|
|
|
2012-10-03 13:45:26 +08:00
|
|
|
def install_rvm_binstubs
|
|
|
|
puts "======================================================"
|
|
|
|
puts "Installing RVM Bundler support. Never have to type"
|
|
|
|
puts "bundle exec again! Please use bundle --binstubs and RVM"
|
|
|
|
puts "will automatically use those bins after cd'ing into dir."
|
|
|
|
puts "======================================================"
|
|
|
|
run %{ chmod +x $rvm_path/hooks/after_cd_bundler }
|
|
|
|
puts
|
|
|
|
end
|
|
|
|
|
2012-09-29 01:38:59 +08:00
|
|
|
def install_homebrew
|
2013-01-27 03:07:46 +08:00
|
|
|
run %{which brew}
|
2013-01-27 03:06:01 +08:00
|
|
|
unless $?.success?
|
|
|
|
puts "======================================================"
|
|
|
|
puts "Installing Homebrew, the OSX package manager...If it's"
|
|
|
|
puts "already installed, this will do nothing."
|
|
|
|
puts "======================================================"
|
|
|
|
run %{ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"}
|
|
|
|
end
|
|
|
|
|
2012-09-29 01:38:59 +08:00
|
|
|
puts
|
|
|
|
puts
|
|
|
|
puts "======================================================"
|
|
|
|
puts "Installing Homebrew packages...There may be some warnings."
|
|
|
|
puts "======================================================"
|
2013-03-29 23:25:27 +08:00
|
|
|
run %{brew install zsh ack ctags git hub tmux reattach-to-user-namespace the_silver_searcher}
|
2012-09-29 01:38:59 +08:00
|
|
|
puts
|
|
|
|
puts
|
|
|
|
end
|
|
|
|
|
|
|
|
def install_fonts
|
|
|
|
puts "======================================================"
|
|
|
|
puts "Installing patched fonts for Powerline."
|
|
|
|
puts "======================================================"
|
|
|
|
run %{ cp -f $HOME/.yadr/fonts/* $HOME/Library/Fonts }
|
|
|
|
puts
|
|
|
|
end
|
|
|
|
|
2013-03-14 19:56:59 +08:00
|
|
|
def install_term_theme
|
|
|
|
puts "======================================================"
|
|
|
|
puts "Installing iTerm2 solarized theme."
|
|
|
|
puts "======================================================"
|
|
|
|
run %{ /usr/libexec/PlistBuddy -c "Add :'Custom Color Presets':'Solarized Light' dict" ~/Library/Preferences/com.googlecode.iterm2.plist }
|
|
|
|
run %{ /usr/libexec/PlistBuddy -c "Merge 'iTerm2/Solarized Light.itermcolors' :'Custom Color Presets':'Solarized Light'" ~/Library/Preferences/com.googlecode.iterm2.plist }
|
|
|
|
run %{ /usr/libexec/PlistBuddy -c "Add :'Custom Color Presets':'Solarized Dark' dict" ~/Library/Preferences/com.googlecode.iterm2.plist }
|
|
|
|
run %{ /usr/libexec/PlistBuddy -c "Merge 'iTerm2/Solarized Dark.itermcolors' :'Custom Color Presets':'Solarized Dark'" ~/Library/Preferences/com.googlecode.iterm2.plist }
|
|
|
|
|
|
|
|
puts "======================================================"
|
|
|
|
puts "To make sure your profile is using the solarized theme"
|
|
|
|
puts "Please check your settings under:"
|
|
|
|
puts "Preferences> Profiles> [your profile]> Colors> Load Preset.."
|
|
|
|
puts "======================================================"
|
|
|
|
end
|
|
|
|
|
2012-09-27 01:23:39 +08:00
|
|
|
def install_prezto
|
2012-10-25 23:09:24 +08:00
|
|
|
puts
|
2012-09-27 01:23:39 +08:00
|
|
|
puts "Installing Prezto (ZSH Enhancements)..."
|
|
|
|
|
|
|
|
unless File.exists?(File.join(ENV['ZDOTDIR'] || ENV['HOME'], ".zprezto"))
|
|
|
|
run %{ ln -nfs "$HOME/.yadr/zsh/prezto" "${ZDOTDIR:-$HOME}/.zprezto" }
|
|
|
|
|
2012-10-20 01:08:42 +08:00
|
|
|
# The prezto runcoms are only going to be installed if zprezto has never been installed
|
|
|
|
file_operation(Dir.glob('zsh/prezto/runcoms/z*'), :copy)
|
|
|
|
end
|
2012-09-27 01:23:39 +08:00
|
|
|
|
2012-10-25 23:09:24 +08:00
|
|
|
puts
|
2012-10-25 22:52:18 +08:00
|
|
|
puts "Overriding prezto ~/.zpreztorc with YADR's zpreztorc to enable additional modules..."
|
|
|
|
run %{ ln -nfs "$HOME/.yadr/zsh/prezto-override/zpreztorc" "${ZDOTDIR:-$HOME}/.zpreztorc" }
|
|
|
|
|
2012-10-25 23:09:24 +08:00
|
|
|
puts
|
2012-09-27 02:05:28 +08:00
|
|
|
puts "Creating directories for your customizations"
|
|
|
|
run %{ mkdir -p $HOME/.zsh.before }
|
|
|
|
run %{ mkdir -p $HOME/.zsh.after }
|
|
|
|
run %{ mkdir -p $HOME/.zsh.prompts }
|
2012-11-26 23:41:35 +08:00
|
|
|
|
2013-03-22 02:24:12 +08:00
|
|
|
if ENV["SHELL"].include? 'zsh' then
|
2013-03-21 21:02:25 +08:00
|
|
|
puts "Zsh is already configured as your shell of choice. Restart your session to load the new settings"
|
|
|
|
else
|
|
|
|
puts "Setting zsh as your default shell"
|
|
|
|
run %{ chsh -s /bin/zsh }
|
|
|
|
end
|
2012-09-27 01:23:39 +08:00
|
|
|
end
|
|
|
|
|
2012-08-10 02:47:45 +08:00
|
|
|
def want_to_install? (section)
|
2012-12-27 07:38:53 +08:00
|
|
|
if ENV["ASK"]=="true"
|
2012-10-25 23:09:24 +08:00
|
|
|
puts "Would you like to install configuration files for: #{section}? [y]es, [n]o"
|
|
|
|
STDIN.gets.chomp == 'y'
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
2012-08-10 02:47:45 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def file_operation(files, method = :symlink)
|
|
|
|
files.each do |f|
|
|
|
|
file = f.split('/').last
|
|
|
|
source = "#{ENV["PWD"]}/#{f}"
|
2012-01-25 14:13:33 +08:00
|
|
|
target = "#{ENV["HOME"]}/.#{file}"
|
|
|
|
|
2012-10-25 23:09:24 +08:00
|
|
|
puts "======================#{file}=============================="
|
|
|
|
puts "Source: #{source}"
|
|
|
|
puts "Target: #{target}"
|
2012-01-25 14:13:33 +08:00
|
|
|
|
2013-03-21 21:21:51 +08:00
|
|
|
if File.exists?(target) && (!File.symlink?(target) || (File.symlink?(target) && File.readlink(target) != source))
|
2012-10-25 23:09:24 +08:00
|
|
|
puts "[Overwriting] #{target}...leaving original at #{target}.backup..."
|
|
|
|
run %{ mv "$HOME/.#{file}" "$HOME/.#{file}.backup" }
|
2012-01-25 14:13:33 +08:00
|
|
|
end
|
|
|
|
|
2012-08-10 02:47:45 +08:00
|
|
|
if method == :symlink
|
2012-10-25 23:09:24 +08:00
|
|
|
run %{ ln -nfs "#{source}" "#{target}" }
|
2012-08-10 02:47:45 +08:00
|
|
|
else
|
|
|
|
run %{ cp -f "#{source}" "#{target}" }
|
|
|
|
end
|
2012-01-25 14:13:33 +08:00
|
|
|
|
2012-08-10 02:47:45 +08:00
|
|
|
# Temporary solution until we find a way to allow customization
|
2012-09-27 01:23:39 +08:00
|
|
|
# This modifies zshrc to load all of yadr's zsh extensions.
|
|
|
|
# Eventually yadr's zsh extensions should be ported to prezto modules.
|
2012-08-10 02:47:45 +08:00
|
|
|
if file == 'zshrc'
|
2012-10-20 01:08:42 +08:00
|
|
|
File.open(target, 'a') do |zshrc|
|
|
|
|
zshrc.puts('for config_file ($HOME/.yadr/zsh/*.zsh) source $config_file')
|
2012-08-10 02:47:45 +08:00
|
|
|
end
|
|
|
|
end
|
2012-01-25 14:13:33 +08:00
|
|
|
|
2012-10-25 23:09:24 +08:00
|
|
|
puts "=========================================================="
|
|
|
|
puts
|
2012-08-10 02:47:45 +08:00
|
|
|
end
|
2012-01-25 14:13:33 +08:00
|
|
|
end
|
|
|
|
|
2013-03-16 22:47:54 +08:00
|
|
|
def needs_migration_to_vundle?
|
|
|
|
File.exists? File.join('vim', 'bundle', 'tpope-vim-pathogen')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def list_vim_submodules
|
|
|
|
result=`git submodule -q foreach 'echo $name"||"\`git remote -v | awk "END{print \\\\\$2}"\`'`.select{ |line| line =~ /^vim.bundle/ }.map{ |line| line.split('||') }
|
|
|
|
Hash[*result.flatten]
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-01-25 14:13:33 +08:00
|
|
|
def success_msg(action)
|
|
|
|
puts ""
|
|
|
|
puts " _ _ _ "
|
|
|
|
puts " | | | | | | "
|
|
|
|
puts " | |___| |_____ __| | ____ "
|
|
|
|
puts " |_____ (____ |/ _ |/ ___) "
|
|
|
|
puts " _____| / ___ ( (_| | | "
|
|
|
|
puts " (_______\_____|\____|_| "
|
|
|
|
puts ""
|
|
|
|
puts "YADR has been #{action}. Please restart your terminal and vim."
|
|
|
|
end
|