Sha256: 5d071e51d148ff9fb5dc8aaded7f57e8e936848b28145cdf2fcab4a3ea3ce904

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

#!/usr/bin/env ruby
#
# Pulls a dotfiles repo and symlinks the files where you specify
#
require 'yaml'
require 'git'
require_relative 'config'

class Dotfiles < Config
  def 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 repo(config['repo'])
      config['files'].each do |k, v|
        link(k, v)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
myosx-0.2.2 lib/myosx/dotfiles.rb