Created
October 26, 2013 01:47
-
-
Save Squidamatron/7164372 to your computer and use it in GitHub Desktop.
Symlink dotfiles, now with more Ruby!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "fileutils" | |
$dotfiles = Dir.home + "/Coding/git/dotfiles" | |
$ff_profile = `awk -F\= '/Path/ {print $2}' ~/.mozilla/firefox/profiles.ini` | |
def symlinkfile(fname) | |
source = File.expand_path($dotfiles+"/"+fname, __FILE__) | |
if fname == "userChrome.css" | |
target = Dir.home + "/.mozilla/firefox/" + $ff_profile.chomp! + "/chrome/" + fname | |
else | |
target = Dir.home + "/." + fname | |
end | |
unless File.exist?(target) | |
puts "Creating symlink: #{target} to #{source}" | |
File.symlink(source, target) | |
else | |
puts "WARNING: #{target} exists" | |
end | |
end | |
def makelinks(path = ".") | |
if path != "." | |
dirpath = File.expand_path(File.join(Dir.home, "." + path)) | |
else | |
dirpath = File.expand_path(File.join(Dir.home, path)) | |
end | |
unless File.exist?(dirpath) | |
puts "mkdir #{dirpath}" | |
FileUtils.mkdir_p(dirpath) | |
end | |
Dir.foreach("#{path}") do |fname| | |
filepath = File.expand_path(File.join(path, fname)) | |
unless fname == __FILE__ || fname[0] == '.' | |
if File.file?(filepath) | |
symlinkfile(fname) | |
elsif File.directory?(filepath) | |
symlinkfile(fname) | |
else | |
puts "Neither file nor directory: #{filepath}" | |
end | |
else | |
puts "Skipping #{fname}" | |
end | |
end | |
end | |
if File.absolute_path(".") != $dotfiles | |
abort("ERROR: Script must be run from " + Dir.home + $dotfiles) | |
end | |
makelinks() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment