Sha256: 971bafd286e9a12178aed0cf61a37df7ad31937e8d983f355ebb704ebbee696e

Contents?: true

Size: 1010 Bytes

Versions: 1

Compression:

Stored size: 1010 Bytes

Contents

require 'exogenesis/abstract_package_manager'

# Links all files in the directory `tilde` to your home directory
class Dotfile < AbstractPackageManager
  def install
    file_names.each { |dotfile| link_file dotfile }
  end

  def teardown
    file_names.each { |dotfile| unlink_file dotfile }
  end

  private

  def link_file(file_name)
    original = File.join Dir.pwd, "tilde", file_name.to_s
    target = File.join Dir.home, ".#{file_name}"

    if File.symlink? target
      puts "#{file_name} already linked"
    else
      puts "Linking #{file_name}"
      `ln -s #{original} #{target}`
    end
  end

  def unlink_file(file_name)
    target = File.join Dir.home, ".#{file_name}"

    if File.symlink? target
      `rm #{target}`
      puts "Symlink for #{target} removed"
    else
      puts "No symlink for #{target} existed."
    end
  end

  def file_names
    file_names = Dir.entries(File.join(Dir.pwd, "tilde"))

    file_names.delete_if do |filename|
      filename[0] == "."
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
exogenesis-0.0.1 lib/exogenesis/dotfile.rb