Sha256: 7c447870720efad69efe0c5fb759568889b59c406897b427b0db0d5094f260d9

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

#!/usr/bin/env ruby

require 'yaml'
require 'git'
require_relative 'config'

class Dotfiles < Config
  def initialize
    @config = $global_config['dotfiles']
  end

  def dotfiledir
    File.join($workspace, 'dotfiles')
  end

  def repo(repo)
    if Git.ls_remote(repo)
      unless File.exist?(dotfiledir)
        puts "Cloning #{dotfile_repo}"
        Git.clone(repo, 'dotfiles', :path => $workspace)
      else
        g = Git.init(dotfiledir)
        puts "Pulling latest #{repo}"
        g.pull
      end
    end
  end

  def link(file, dest)
    source_file = "#{dotfiledir}/#{file}"

    dest = File.expand_path(dest)
    raise "#{source_file} doesn't exist! Check your config or repo" unless File.exist?(source_file)

    if File.exist?(dest)
      File.delete(dest)
    end

    puts "Linking #{source_file} to #{dest}"
    File.symlink(source_file, dest)
  end

  def exec
    if @config['manage']
      if repo(@config['repo'])
        @config['files'].each do |k, v|
          link(k, v)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
myosx-0.2.1 lib/myosx/dotfiles.rb
myosx-0.1.0 lib/myosx/dotfiles.rb