require 'rubygems' require 'rake' module Enumerable def like?(val, op = :===) any? {|i| i.__send__(op, val) } end end class String def expand File.expand_path(self) end def exist? File.exist?(self.expand) end end SOURCE_DIR = '~/dotfiles'.expand TARGET_DIR = '~'.expand directory SOURCE_DIR directory TARGET_DIR cd SOURCE_DIR EXCLUDE_FILES = [/\.$/, '.git'] DOTFILES = FileList['.*'].reject {|f| EXCLUDE_FILES.like?(f) } task :default do if '#{SOURCE_DIR}/.git'.exist? sh 'git pull' else sh 'git clone git@github.com:aereal/dotfiles.git .' end end desc 'Installing dotfiles in your home directory' task :install do DOTFILES.each do |f| ln_sf "#{SOURCE_DIR}/#{f}, "#{TARGET_DIR}/#{f}" end end desc 'Remove symlink' task :uninstall do DOTFILES.each do |f| rm "#{TARGET_DIR}/#{f}" end end
使い方としてこんなかんじ:
$ cd ~ $ wget http://github.com/aereal/dotfiles/raw/master/Rakefile $ rake && rake install
rakeについて調べてみたんだけど便利ですね。コンパイルをしない、こんなかんじの用途でもじゅうぶんありがたみを感じる。