Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Commit

Permalink
Make config windows compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Christy committed Oct 31, 2011
1 parent 9663f3e commit 6c485eb
Show file tree
Hide file tree
Showing 9 changed files with 2,969 additions and 51 deletions.
17 changes: 16 additions & 1 deletion .gvimrc
Expand Up @@ -9,7 +9,22 @@
set guioptions-=L

" go full screen like you mean it
set fuoptions=maxvert,maxhorz
if has('win32')
au GUIEnter * simalt ~x
elseif has('mac')
set fuoptions=maxvert,maxhorz
endif

" set a valid swap file location
if has('win32')
set directory=%TEMP%
endif

" turn off beeping and prevent screen lighting flash
if has('win32')
set noerrorbells visualbell t_vb=
autocmd GUIEnter * set visualbell t_vb=
endif

" use a big, pretty font
set guifont=Monaco:h15
Expand Down
3 changes: 2 additions & 1 deletion .vimrc
@@ -1,4 +1,5 @@
" bring in the bundles
" bring in the bundles for mac and windows
set rtp+=~/vimfiles/vundle.git/
set rtp+=~/.vim/vundle.git/
call vundle#rc()

Expand Down
22 changes: 17 additions & 5 deletions README.md
Expand Up @@ -4,15 +4,26 @@ You should give it a try.

## Pre-requisites

This config is built primarily to work on top of the OSX version of `MacVim`, but should be usable on top of other `vim` or `gvim`
installations that are built with all of the `vim` features necessary to support the used plugins.
This config is built primarily to work on top of the OSX version of `MacVim`, but should be usable on top of other `vim` or `gvim` installations that are built with all of the `vim` features necessary to support the used plugins.

## Attention Windows Users!

If you are installing this config on Microsoft Windows, you must download and install the latest [RailsInstaller](http://www.railsinstaller.org/) package. Go ahead and do it now. I'll wait.

Install the latest version of [Vim](http://www.vim.org/download.php#pc) and install with default options + checking the "Create .bat files for command line use".

The Windows version of the Vim configuration uses rake (for installation) git (for Vim plugin installations), and requires several other packages to emulate Ack (for file searching) and Curl (for gists) under Windows. RailsInstaller is a single package that installs everything we will need to get things working.

## Install

Windows users: be sure to use **RailsInstaller** > **Command Prompt with Ruby and Rails** instead of the normal command prompt.

1. `git clone git://github.com/edgecase/vim-config.git`
2. `rake` (This will symlink the necessary files to your home directory, asking for permission before clobbering anything.)
3. `vim`
4. `:BundleInstall` (This will clone and install all of the plugins from github.)
2. `cd vim-config`
3. (beta!) Get the windows branch: `git checkout windows`
4. `rake` (This will symlink the necessary files to your home directory, asking for permission before clobbering anything.)
5. `vim` (or in Windows, `gvim`)
6. `:BundleInstall` (This will clone and install all of the plugins from github.)

## Customizing

Expand Down Expand Up @@ -381,3 +392,4 @@ popular color themes](http://www.vi-improved.org/color_sampler_pack/):

Use `:color vibrantink` to switch to a color scheme.


91 changes: 47 additions & 44 deletions Rakefile
@@ -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
36 changes: 36 additions & 0 deletions lib/installer.rb
@@ -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
46 changes: 46 additions & 0 deletions lib/translation.rb
@@ -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
10 changes: 10 additions & 0 deletions windows/ack.bat
@@ -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" %*

0 comments on commit 6c485eb

Please sign in to comment.