Class: Dotfiles
- Inherits:
-
Object
- Object
- Dotfiles
- Defined in:
- lib/myosx/dotfiles.rb
Instance Method Summary collapse
- #config ⇒ Object
- #dotfiledir ⇒ Object
- #exec ⇒ Object
- #link(file, dest) ⇒ Object
- #repo(repo, target, local_repo = 'dotfiles') ⇒ Object
Instance Method Details
#config ⇒ Object
11 12 13 |
# File 'lib/myosx/dotfiles.rb', line 11 def config Konfig.new.global['dotfiles'] end |
#dotfiledir ⇒ Object
15 16 17 |
# File 'lib/myosx/dotfiles.rb', line 15 def dotfiledir File.join(Konfig.new.workspace_directory, 'dotfiles') end |
#exec ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/myosx/dotfiles.rb', line 50 def exec if repo(config['repo'], dotfiledir) config['files'].each do |file, dest| link("#{dotfiledir}/#{file}", dest) end end end |
#link(file, dest) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/myosx/dotfiles.rb', line 32 def link(file, dest) dest = File.(dest) raise "#{file} doesn't exist! Check your config or repo" unless File.exist?(file) if File.symlink?(dest) File.delete(dest) end if File.exist?(dest) backup_file = "#{dest}.#{Date.today.to_s}" puts "Creating backup of #{dest} called: #{backup_file}" File.rename(dest, backup_file) end puts "Linking #{file} to #{dest}" File.symlink(file, dest) end |
#repo(repo, target, local_repo = 'dotfiles') ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/myosx/dotfiles.rb', line 19 def repo(repo, target, local_repo = 'dotfiles') if Git.ls_remote(repo) unless File.exist?(target) puts "Cloning #{repo}" Git.clone(repo, local_repo, :path => File.dirname(target)) else g = Git.init(target) puts "Pulling latest #{repo}" g.pull end end end |