module Core

Public Class Methods

delete(name) click to toggle source
# File lib/dotfiles/core.rb, line 113
def self.delete(name)
  path = Get.exists(name)

  FileUtils.rm_rf(path)
end
help(command=nil) click to toggle source
# File lib/dotfiles/core.rb, line 38
def self.help(command=nil)
  if command == nil
    Response.help
    exit
  end

  case command.downcase
    when 'install'
      Response.install
    when 'use'
      Response.use
    when 'save'
      Response.save
    when 'delete'
      Response.delete
    else
      Response.help
  end
  exit
end
install(link) click to toggle source
# File lib/dotfiles/core.rb, line 59
def self.install(link)
  name = Get.name
  path = Get.path(name)

  begin
    Git.clone(link, path)
  rescue Exception => e
    puts "#{"Error".red}: Could not clone the repository"
    puts
    puts e.message
    exit
  end

  puts "#{name.cyan} #{"successfully installed".green}"
  puts "Path: #{path}"

  print 'Do you want to use the installed dotfiles? (Y/n) '
  use = Get.answer

  if use
    use(name)
  end
end
save() click to toggle source
# File lib/dotfiles/core.rb, line 96
def self.save
  name = Get.name
  path = Get.path(name)

  init(path)

  config(path)
  tools(path)

  print 'Do you also want to backup your /etc directory? (Y/n) '
  backup = Get.answer
  
  if backup
    etc(path)
  end
end
use(name) click to toggle source
# File lib/dotfiles/core.rb, line 83
def self.use(name)
  path = Get.exists(name)

  print 'Backup current dotfiles? (Y/n) '
  save = Get.answer

  if save
    save()
  end

  scan(name, path)
end

Private Class Methods

config(path) click to toggle source
# File lib/dotfiles/core.rb, line 127
def self.config(path)
  contents = FileSystem.contents(@@config)
  path+='config/'

  Sudo.copy(contents, path)
end
etc(path) click to toggle source
# File lib/dotfiles/core.rb, line 144
def self.etc(path)
  contents = FileSystem.contents(@@etc)
  path+='etc/'

  Dir.mkdir(path)
  Sudo.copy(contents, path)
end
init(path) click to toggle source
# File lib/dotfiles/core.rb, line 121
def self.init(path)
  Dir.mkdir(path)
  Dir.mkdir(path+'config/')
  Dir.mkdir(path+'tools/')
end
scan(name, path) click to toggle source
# File lib/dotfiles/core.rb, line 152
def self.scan(name, path)
  # ~/.dotfiles/name/etc
  etc = path+'etc/'
  if File.exists?(etc)
    Install.config(etc)
  end

  # ~/.dotfiles/name/config
  config = path+'config/'
  if File.exists?(config)
    Install.config(config)
  end

  # ~/.dotfiles/name/tools
  tools = path+'tools/'
  if File.exists?(tools)
    Install.tools(tools)
  end

  # ~/.dotfiles/name/scripts
  scripts = path+'scripts/'
  if File.exists?(scripts)
    Install.scripts(name, scripts)
  end

  # ~/.dotfiles/name/wallpapers
  wallpapers = path+'wallpapers/'
  if File.exists?(wallpapers)
    Install.wallpapers(name, wallpapers)
  end
end
tools(path) click to toggle source
# File lib/dotfiles/core.rb, line 134
def self.tools(path)
  # Returns an array of ~/.* files
  contents = FileSystem.rglob(@@root)
  path+='tools/'

  contents.each do |file|
    Sudo.copy(file, path)
  end
end