-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aaron Christy
committed
Oct 31, 2011
1 parent
9663f3e
commit 6c485eb
Showing
9 changed files
with
2,969 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,78 @@ | ||
require 'rubygems' | ||
require 'rake' | ||
require './lib/installer' | ||
require './lib/translation' | ||
|
||
desc "symlink vim files" | ||
task :default do | ||
symlinkage %w[ .vimrc .gvimrc .vim ] | ||
# install vundle | ||
system "git clone http://github.com/gmarik/vundle.git ~/.vim/vundle.git" | ||
end | ||
MAC_FILES = | ||
{ '.vimrc' => '~/.vimrc', | ||
'.gvimrc' => '~/.gvimrc', | ||
'.vim' => '~/.vim' } | ||
|
||
WINDOW_FILES = | ||
{ '.vimrc' => '~/_vimrc', | ||
'.gvimrc' => '~/_gvimrc', | ||
'.vim' => '~/vimfiles', | ||
'windows/ack.bat' => 'c:\RailsInstaller\Git\cmd\ack.bat', | ||
'windows/ack.pl' => 'c:\RailsInstaller\Git\cmd\ack.pl', | ||
'windows/curl.cmd' => 'c:\RailsInstaller\Git\cmd\curl.cmd' } | ||
|
||
def symlinkage(files) | ||
files.each do |file| | ||
desc "Install vim configuration and plugin files" | ||
task :default do | ||
installer = Installer.new(platform_files) | ||
installer.files.each do |f| | ||
case | ||
when file_identical?(file) then skip_identical_file(file) | ||
when replace_all_files? then link_file(file) | ||
when file_missing?(file) then link_file(file) | ||
else prompt_to_link_file(file) | ||
when f.identical? then skip_file(f) | ||
when replace_all? then auto_link_files(f) | ||
when f.safe_to_link? then auto_link_files(f) | ||
else prompt_to_link_files(f) | ||
end | ||
end | ||
Rake::Task['vundle'].execute | ||
end | ||
|
||
|
||
# FILE CHECKS | ||
def file_exists?(file) | ||
File.exists?("#{ENV['HOME']}/#{file}") | ||
desc "Install vundle for vim plugins" | ||
task :vundle do | ||
target = "#{platform_files['.vim']}/vundle.git" | ||
Installer.git_clone('http://github.com/gmarik/vundle.git', target) | ||
puts "\nIf this is a new installation, open vim and type ':BundleInstall' to install necessary plugins." | ||
end | ||
|
||
def file_missing?(file) | ||
!file_exists?(file) | ||
def platform_files | ||
Installer.windows? ? WINDOW_FILES : MAC_FILES | ||
end | ||
|
||
def file_identical?(file) | ||
File.identical? file, File.join(ENV['HOME'], "#{file}") | ||
end | ||
|
||
def replace_all_files? | ||
@replace_all == true | ||
end | ||
|
||
|
||
# FILE ACTIONS | ||
def prompt_to_link_file(file) | ||
print "overwrite? ~/#{file} [ynaq] " | ||
def prompt_to_link_files(file) | ||
print "overwrite? #{file.target} [ynaq] " | ||
case $stdin.gets.chomp | ||
when 'y' then replace_file(file) | ||
when 'y' then replace(file) | ||
when 'a' then replace_all(file) | ||
when 'q' then exit | ||
else skip_file(file) | ||
else skip_file(file) | ||
end | ||
end | ||
|
||
def link_file(file) | ||
puts " => symlinking #{file}" | ||
directory = File.dirname(__FILE__) | ||
sh("ln -s #{File.join(directory, file)} #{ENV['HOME']}/#{file}") | ||
def link_files(file) | ||
puts " => symlinking #{file.source} to #{file.target}" | ||
file.link | ||
end | ||
|
||
def replace_file(file) | ||
sh "rm -rf #{ENV['HOME']}/#{file}" | ||
link_file(file) | ||
def replace(file) | ||
puts " => replacing #{file.source} with #{file.target}" | ||
file.force_link | ||
end | ||
|
||
def replace_all(file) | ||
@replace_all = true | ||
replace_file(file) | ||
replace(file) | ||
end | ||
|
||
def replace_all? | ||
@replace_all == true | ||
end | ||
|
||
def skip_file(file) | ||
puts " => skipping ~/#{file}" | ||
puts " => skipping #{file.target}" | ||
end | ||
|
||
def skip_identical_file(file) | ||
puts " => skipping identical ~/#{file}" | ||
def auto_link_files(file) | ||
file.safe_to_link? ? link_files(file) : replace(file) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'fileutils' | ||
require 'rake/win32' | ||
|
||
class Installer | ||
attr_accessor :translations, :files | ||
|
||
def initialize(translations) | ||
@translations = translations | ||
@files = translations.map { |k,v| Translation.new(k, v) } | ||
end | ||
|
||
def self.windows? | ||
Rake::Win32.windows? | ||
end | ||
|
||
def self.git_clone(repo, target) | ||
path = translate_path(target) | ||
FileUtils.rm_rf(path) if File.exists?(path) | ||
`git clone ""#{repo}"" "#{target}"` | ||
end | ||
|
||
def self.home_join(*files) | ||
normalize(File.join(ENV['HOME'], files)) | ||
end | ||
|
||
def self.translate_path(path) | ||
if path[0].chr === '~' | ||
path[0] = ENV['HOME'] | ||
end | ||
normalize(path) | ||
end | ||
|
||
def self.normalize(path) | ||
Rake::Win32.normalize(path) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'rake/win32' | ||
require 'fileutils' | ||
require 'pathname' | ||
require File.join(File.dirname(__FILE__), 'installer') | ||
|
||
class Translation | ||
attr_accessor :source, :target | ||
|
||
def initialize(source_path, target_path) | ||
@source = pathname(source_path) | ||
@target = pathname(target_path) | ||
end | ||
|
||
def link | ||
raise "This source file does not exist: #{source}" unless source_exists? | ||
`ln -s \"#{source}\" \"#{target}\"` | ||
end | ||
|
||
def force_link | ||
FileUtils.rm_rf(target) && link | ||
end | ||
|
||
def safe_to_link? | ||
identical? || !target_exists? | ||
end | ||
|
||
def source_exists? | ||
File.exists?(source) | ||
end | ||
|
||
def target_exists? | ||
File.exists?(target) | ||
end | ||
|
||
def identical? | ||
File.identical?(source, target) | ||
end | ||
|
||
private | ||
|
||
def pathname(file) | ||
path = Installer.translate_path(file) | ||
Pathname.new(path).expand_path | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@rem Do not use "echo off" to not affect any child calls. | ||
@setlocal | ||
|
||
@rem Get the abolute path to the parent directory, which is assumed to be the | ||
@rem Git installation root. | ||
@for /F "delims=" %%I in ("%~dp0..") do @set git_install_root=%%~fI | ||
@set PATH=%git_install_root%\bin;%git_install_root%\cmd;%git_install_root%\mingw\bin;%PATH% | ||
@set _cwd=%~dp0 | ||
|
||
@perl.exe "%_cwd%ack.pl" %* |
Oops, something went wrong.