Module: Dotbot

Defined in:
lib/dotbot.rb,
lib/dotbot/cli.rb,
lib/dotbot/config.rb,
lib/dotbot/errors.rb,
lib/dotbot/version.rb

Overview

All the custom errors for this dotfile manager

Defined Under Namespace

Classes: CLI, Config, DoesNotExistError, DotbotError, GitError, NoConfigError

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.track(filepath, config, git) ⇒ Object

Raises:



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dotbot.rb', line 7

def self.track(filepath, config, git)
  original_full_path = File.expand_path(filepath)
  raise DoesNotExistError.new(filepath) unless File.exist?(original_full_path)

  dotbot_dir = File.expand_path(config.dir)
  FileUtils.cp(original_full_path, dotbot_dir)
  FileUtils.rm(original_full_path)
  new_full_path = File.join(dotbot_dir, File.basename(filepath))
  FileUtils.ln_s(new_full_path, original_full_path)

  if git
    Dir.chdir(config.dir)
    `git add #{new_full_path}`
    `git commit -m "Dotbot added #{File.basename(filepath)} to the repo"`
    `git push`
  end

  raise GitError.new("track") unless $? == 0

  puts "👾  : #{filepath} is now tracked!"
end

.update(config) ⇒ Object

Raises:



29
30
31
32
33
34
35
# File 'lib/dotbot.rb', line 29

def self.update(config)
  dotbot_dir = File.expand_path(config.dir)
  Dir.chdir(dotbot_dir)
  `git pull`
  raise GitError.new("update") unless $? == 0
  puts "👾  : Dotfiles updated!"
end