Created
December 1, 2014 20:51
-
-
Save myronmarston/61cc10b6bdb35a1eceba to your computer and use it in GitHub Desktop.
dotfiles Rakefile
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
require 'pathname' | |
HOME_DIR = Pathname("~").expand_path | |
def symlink_files_for_dir(to_symlink) | |
to_symlink = to_symlink.expand_path | |
to_symlink_root = Pathname("./to_symlink").expand_path | |
to_symlink.children.each do |child| | |
relative = child.relative_path_from(to_symlink_root) | |
symlink = HOME_DIR + ".#{relative}" | |
if !symlink.exist? | |
sh "ln -s #{child} #{symlink}" | |
elsif symlink.symlink? && symlink.realpath == child | |
puts "Skipping #{symlink} because it is already symlinked properly" | |
elsif symlink.directory? | |
symlink_files_for_dir(child) | |
else | |
warn "WARNING: #{symlink} already exists and is not the desired symlink. Skipping." | |
end | |
end | |
end | |
desc "Symlink dot files" | |
task :symlink do | |
symlink_files_for_dir(Pathname("./to_symlink")) | |
end | |
# TODO: make this install janus as well... | |
desc "Install my Janus customized vim files" | |
task :install_plugins do | |
extra_plugins = %w[ | |
git://github.com/vim-scripts/bufexplorer.zip.git | |
] | |
Dir.chdir(File.expand_path("~#{ENV['USER']}")) do | |
FileUtils.mkdir_p('.janus') | |
Dir.chdir('.janus') do | |
extra_plugins.each do |plugin| | |
dir = plugin.split('/').last.gsub(/.git$/, '') | |
if File.exist?(dir) | |
puts "Updating #{dir}..." | |
Dir.chdir(dir) { sh "git pull --rebase" } | |
else | |
puts "Installing #{dir}..." | |
sh "git clone #{plugin}" | |
end | |
end | |
end | |
end | |
end | |
desc "Install all dot files" | |
task :install => [:symlink, :install_plugins] | |
task :default => :install |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment