Last active
July 22, 2023 07:44
-
-
Save jmlrt/3e3ce65a606dd49b3f7b 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 '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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rakefile used to manage dotfiles: