#!/usr/bin/env ruby require 'optparse' require 'methadone' require 'fullstop' require 'fileutils' class App include Methadone::Main include Methadone::CLILogging include Methadone::SH include Fullstop main do |repo_url| Dir.chdir options['checkout-dir'] do repo = Repo.clone_from(repo_url,options[:force]) repo.files do |file| link_file(repo,file,options[:force]) end end info "Dotfiles symlinked" end def self.link_file(repo,file,overwrite) source_file = File.join(repo.repo_dir,file) FileUtils.rm(file) if File.exists?(file) && overwrite FileUtils.ln_s source_file,'.' end version Fullstop::VERSION description 'Manages dotfiles from a git repo' options['checkout-dir'] = ENV['HOME'] on("--force","Overwrite files if they exist") on("-d DIR","--checkout-dir","Where to clone the repo") arg :repo_url use_log_level_option go! end