Prezto support! Make sure you run rake:install
This commit is contained in:
119
Rakefile
119
Rakefile
@@ -9,60 +9,21 @@ task :install => [:submodules] do
|
||||
puts "be overwritten without your consent."
|
||||
puts "======================================================"
|
||||
puts
|
||||
# this has all the linkables from this directory.
|
||||
linkables = []
|
||||
linkables += Dir.glob('git/*') if want_to_install?('git')
|
||||
linkables += Dir.glob('irb/*') if want_to_install?('irb/pry')
|
||||
linkables += Dir.glob('ruby/*') if want_to_install?('ruby (gems)')
|
||||
linkables += Dir.glob('ctags/*') if want_to_install?('ctags config (better js/ruby support)')
|
||||
linkables += Dir.glob('vimify/*') if want_to_install?('vimification of mysql/irb/command line')
|
||||
linkables += Dir.glob('{vim,vimrc}') if want_to_install?('vim')
|
||||
linkables += Dir.glob('zsh/zshrc') if want_to_install?('zsh')
|
||||
Rake::Task['zsh_themes'].invoke
|
||||
# this has all the runcoms from this directory.
|
||||
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)')
|
||||
file_operation(Dir.glob('ctags/*')) if want_to_install?('ctags config (better js/ruby support)')
|
||||
file_operation(Dir.glob('vimify/*')) if want_to_install?('vimification of command line tools')
|
||||
file_operation(Dir.glob('{vim,vimrc}')) if want_to_install?('vim configuration (highly recommended)')
|
||||
|
||||
skip_all = false
|
||||
overwrite_all = false
|
||||
backup_all = false
|
||||
|
||||
linkables.each do |linkable|
|
||||
file = linkable.split('/').last
|
||||
source = "#{ENV["PWD"]}/#{linkable}"
|
||||
target = "#{ENV["HOME"]}/.#{file}"
|
||||
|
||||
puts "--------"
|
||||
puts "file: #{file}"
|
||||
puts "source: #{source}"
|
||||
puts "target: #{target}"
|
||||
|
||||
if File.exists?(target) || File.symlink?(target)
|
||||
unless skip_all || overwrite_all || backup_all
|
||||
puts "File already exists: #{target}, what do you want to do? [s]kip, [S]kip all, [o]verwrite, [O]verwrite all, [b]ackup, [B]ackup all"
|
||||
case STDIN.gets.chomp
|
||||
when 'o' then overwrite = true
|
||||
when 'b' then backup = true
|
||||
when 'O' then overwrite_all = true
|
||||
when 'B' then backup_all = true
|
||||
when 'S' then skip_all = true
|
||||
end
|
||||
end
|
||||
FileUtils.rm_rf(target) if overwrite || overwrite_all
|
||||
run %{ mv "$HOME/.#{file}" "$HOME/.#{file}.backup" } if backup || backup_all
|
||||
end
|
||||
run %{ ln -s "#{source}" "#{target}" }
|
||||
if want_to_install?('zsh enhancements & prezto')
|
||||
install_prezto
|
||||
end
|
||||
|
||||
success_msg("installed")
|
||||
end
|
||||
|
||||
task :zsh_themes do
|
||||
if File.exist?("#{ENV['HOME']}/.oh-my-zsh/modules/prompt/functions")
|
||||
puts "Detected prezto (oh-my-zsh @sorin-ionescu)."
|
||||
run %{ ln -nfs #{ENV["PWD"]}/oh-my-zsh/modules/prompt/functions/* $HOME/.oh-my-zsh/modules/prompt/functions/ } if want_to_install?('zsh themes')
|
||||
elsif File.exist?("#{ENV['HOME']}/.oh-my-zsh")
|
||||
puts "Detected oh-my-zsh @robbyrussell."
|
||||
run %{ ln -nfs #{ENV["PWD"]}/oh-my-zsh/themes/* $HOME/.oh-my-zsh/themes/ } if want_to_install?('zsh themes')
|
||||
end
|
||||
end
|
||||
|
||||
desc "Init and update submodules."
|
||||
task :submodules do
|
||||
sh('git submodule update --init')
|
||||
@@ -78,11 +39,71 @@ def run(cmd)
|
||||
`#{cmd}` unless ENV['DEBUG']
|
||||
end
|
||||
|
||||
def install_prezto
|
||||
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" }
|
||||
end
|
||||
|
||||
file_operation(Dir.glob('zsh/prezto/runcoms/z*'), :copy)
|
||||
|
||||
puts "Installing YADR themes for Prezto..."
|
||||
run %{ ln -nfs $HOME/.yadr/zsh/prezto-themes/modules/prompt/functions/* $HOME/.zprezto/modules/prompt/functions}
|
||||
end
|
||||
|
||||
def want_to_install? (section)
|
||||
puts "Would you like to install configuration files for: #{section}? [y]es, [n]o"
|
||||
STDIN.gets.chomp == 'y'
|
||||
end
|
||||
|
||||
def file_operation(files, method = :symlink)
|
||||
skip_all = false
|
||||
overwrite_all = false
|
||||
backup_all = false
|
||||
|
||||
files.each do |f|
|
||||
file = f.split('/').last
|
||||
source = "#{ENV["PWD"]}/#{f}"
|
||||
target = "#{ENV["HOME"]}/.#{file}"
|
||||
|
||||
puts "--------"
|
||||
puts "file: #{file}"
|
||||
puts "source: #{source}"
|
||||
puts "target: #{target}"
|
||||
|
||||
if File.exists?(target) || File.symlink?(target)
|
||||
unless skip_all || overwrite_all || backup_all
|
||||
puts "File already exists: #{target}, what do you want to do? [s]kip, [S]kip all, [o]verwrite, [O]verwrite all, [b]ackup, [B]ackup all"
|
||||
case STDIN.gets.chomp
|
||||
when 'o' then overwrite = true when 'b' then backup = true
|
||||
when 'O' then overwrite_all = true
|
||||
when 'B' then backup_all = true
|
||||
when 'S' then skip_all = true
|
||||
end
|
||||
end
|
||||
FileUtils.rm_rf(target) if overwrite || overwrite_all
|
||||
run %{ mv "$HOME/.#{file}" "$HOME/.#{file}.backup" } if backup || backup_all
|
||||
end
|
||||
|
||||
if method == :symlink
|
||||
run %{ ln -s "#{source}" "#{target}" }
|
||||
else
|
||||
run %{ cp -f "#{source}" "#{target}" }
|
||||
end
|
||||
|
||||
# Temporary solution until we find a way to allow customization
|
||||
# This modifies zshrc to load all of yadr's zsh extensions.
|
||||
# Eventually yadr's zsh extensions should be ported to prezto modules.
|
||||
if file == 'zshrc'
|
||||
File.open(target, 'a') do |f|
|
||||
f.puts('for config_file ($HOME/.yadr/zsh/*.zsh) source $config_file')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
def success_msg(action)
|
||||
puts ""
|
||||
puts " _ _ _ "
|
||||
|
||||
Reference in New Issue
Block a user