Class: GitConfig

Inherits:
Thor
  • Object
show all
Defined in:
lib/config/git_config.rb

Instance Method Summary collapse

Instance Method Details

#code(*args) ⇒ Object



66
67
68
69
70
71
# File 'lib/config/git_config.rb', line 66

def code(*args)
  Log::LOGGER.info("Open '#{Config::CONFIG_DIR}' in code")
  Dir.chdir(Config::CONFIG_DIR) do
    system 'code', '.', *args
  end
end

#exec(*args) ⇒ Object



59
60
61
62
63
# File 'lib/config/git_config.rb', line 59

def exec(*args)
  Dir.chdir(Config::CONFIG_DIR) do
    system 'git', *args
  end
end

#init(repo) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/config/git_config.rb', line 9

def init(repo)
  force = options['force']

  if File.exist? Config::CONFIG_DIR
    if force
      FileUtils.rm_rf(Config::CONFIG_DIR)
    else
      Log::LOGGER.error("Config already exists at '#{Config::CONFIG_DIR}'")
      abort("Config already exists at '#{Config::CONFIG_DIR}'")
    end
  end

  `git clone #{repo} #{Config::CONFIG_DIR}`
end

#nvim(*args) ⇒ Object



74
75
76
77
78
79
# File 'lib/config/git_config.rb', line 74

def nvim(*args)
  Log::LOGGER.info("Open '#{Config::CONFIG_DIR}' in nvim")
  Dir.chdir(Config::CONFIG_DIR) do
    system 'nvim', '.', *args
  end
end

#pull(*args) ⇒ Object



52
53
54
55
56
# File 'lib/config/git_config.rb', line 52

def pull(*args)
  Dir.chdir(Config::CONFIG_DIR) do
    system 'git', 'pull', *args
  end
end

#status(*args) ⇒ Object



45
46
47
48
49
# File 'lib/config/git_config.rb', line 45

def status(*args)
  Dir.chdir(Config::CONFIG_DIR) do
    system 'git', 'status', *args
  end
end

#updateObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/config/git_config.rb', line 26

def update
  message = options['message']
  Dir.chdir(Config::CONFIG_DIR) do
    changes = `git status --porcelain=v1`
    num_changes = changes.split.length

    if num_changes.zero?
      Log::LOGGER.error("No changes to commit in '#{Config::CONFIG_DIR}'")
      abort("No changes to commit in '#{Config::CONFIG_DIR}'")
    else
      Log::LOGGER.info('Commit changes')
      system 'git', 'add', '.'
      system 'git', 'commit', '-m', "'#{message}'"
      system 'git', 'push'
    end
  end
end