Permalink
Browse files

Rakefile: Refine the Rake task to install dotfiles

  • Loading branch information...
aereal committed Jan 21, 2014
1 parent c6bc19a commit 513bb79cb04341b8029b1c10d019b64eda1647cc
Showing with 28 additions and 38 deletions.
  1. +4 −0 .dotfiles.ignore
  2. +0 −20 .dotfiles.yml
  3. +24 −18 Rakefile
View
@@ -0,0 +1,4 @@
.git
.gitmodules
.travis.yml
.dotfiles.ignore
View

This file was deleted.

Oops, something went wrong.
View
@@ -12,12 +12,9 @@ require 'bootstrap/sync_file_task'
HOME = ENV['HOME']
SRC_DIR = File.dirname(File.expand_path(__FILE__))
REPOSITORY = SRC_DIR
DST_DIR = ENV.fetch('DOTFILES_INSTALL_DIR', HOME)
CONFIG = YAML.load_file(File.join(REPOSITORY, '.dotfiles.yml'))
DOTFILES = CONFIG['dotfiles']
DOTFILES_MAP = DOTFILES.map {|f|
{ basename: f, source: File.join(SRC_DIR, f), installed: File.join(DST_DIR, f) }
}
DEST_DIR = ENV.fetch('DOTFILES_INSTALL_DIR', HOME)
IGNORED_DOTFILES = FileList.new(*File.read('.dotfiles.ignore').split("\n"))
DOTFILES_SRCS = FileList['.[^.]*'].exclude(*IGNORED_DOTFILES)
DEFAULTS_SCRIPTS = FileList['osx/defaults/**/*.bash']
# }}}
@@ -51,26 +48,35 @@ SyncFileTask.new("setup:memo") do |t|
t.destination_file = File.expand_path("~/memo")
t.install_method = :symlink
end
DOTFILES_MAP.each do |dotfile|
file dotfile[:installed] do
ln_sf dotfile[:source], dotfile[:installed]
end
end
# }}}
# Tasks {{{
Rake::TestTask.new(:test) do |t|
t.pattern = 'test/**/*_test.rb'
end
desc "Install dotfiles to $HOME"
task :install => DOTFILES_MAP.map {|dotfile| dotfile[:installed] }
namespace :dotfiles do
desc "Install dotfiles"
task :install => [:check_link, :_install]
task :check_link => DOTFILES_SRCS do |t|
destination_files = t.prerequisites.
map {|prereq| File.join(DEST_DIR, prereq) }.
select {|dest| File.exist?(dest) }
destination_files.each do |dest|
link_dir = File.dirname(File.readlink(dest))
unless FileTest.symlink?(dest) && link_dir == SRC_DIR
abort "Unknown (not managed yet) file: #{dest}"
end
end
end
desc "Show all dotfiles"
task :list do
DOTFILES.each do |dotfile|
puts dotfile
task :_install => DOTFILES_SRCS do |t|
t.prerequisites.each do |prereq|
src = File.join(SRC_DIR, prereq)
dest = File.join(DEST_DIR, prereq)
ln_sf src, dest
end
end
end

0 comments on commit 513bb79

Please sign in to comment.