Skip to content

Instantly share code, notes, and snippets.

@jmlrt
Last active July 22, 2023 07:44
Show Gist options
  • Save jmlrt/3e3ce65a606dd49b3f7b to your computer and use it in GitHub Desktop.
Save jmlrt/3e3ce65a606dd49b3f7b to your computer and use it in GitHub Desktop.
Dotfiles Rakefile
require 'date'
date = DateTime.now.strftime("%Y%m%d%H%M")
$homedir = Dir.home
$dotfiles = [ '.bash_profile', '.bashrc', '.gitconfig', '.kshrc', '.profile', '.tmux.conf', '.vimrc' ]
desc "backup dotfiles"
task :backup do |t|
backupdir = File.join($homedir,"/",t.name)
backupfile = "dotfiles-home.#{date}.tar"
Dir.mkdir(backupdir, 0700) unless Dir.exist?(backupdir)
sh "tar cf #{backupdir}/#{backupfile} -C #{$homedir} #{$dotfiles.join(' ')}", :verbose => true
end
desc "deploy dotfiles"
task :deploy => [ :backup, :diff ] do
$dotfiles.each do |f|
FileUtils.install f, File.join($homedir,f), :mode => 600, :verbose => true
end
end
desc "commit changes to git"
task :commit do
sh "git add Rakefile #{$dotfiles.join(' ')}", :verbose => true
sh "git commit", :verbose => true
end
desc "show differences between current dotfiles and those in repo"
task :diff do
$dotfiles.each do |f|
puts f.upcase
sh "diff #{f} #{$homedir}/#{f}", :verbose => true
end
end
@jmlrt
Copy link
Author

jmlrt commented May 26, 2015

Rakefile used to manage dotfiles:

  • backup
  • deploy
  • commit to git
  • diff between src and current

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment