Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Created December 1, 2014 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myronmarston/61cc10b6bdb35a1eceba to your computer and use it in GitHub Desktop.
Save myronmarston/61cc10b6bdb35a1eceba to your computer and use it in GitHub Desktop.
dotfiles Rakefile
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