class MacSetup::SymlinkInstaller
Public Class Methods
install_symlinks(config)
click to toggle source
# File lib/mac_setup/symlink_installer.rb, line 99 def self.install_symlinks(config) config.symlinks.each do |source_path, target_path| # source = Symlink.new(source_path: File.expand_path(source_path)) # source.link source = Pathname.new(source_path).expand_path short_source_path = MacSetup.shorten_path(source.to_s) unless source.exist? MacSetup.log "#{short_source_path} doesn't exist. Skipping." next end target = Pathname.new(target_path).expand_path short_target_path = MacSetup.shorten_path(target.to_s) MacSetup.log "Linking #{short_source_path} to #{short_target_path}..." home = Pathname.new(ENV.fetch("HOME")) if target.directory? filename = target == home ? ".#{source.basename}" : source.basename full_target = target.join(filename) link(source, full_target) elsif target.to_s.end_with?("/") target.mkpath full_target = target.join(source.basename) link(source, full_target) else target.dirname.mkpath link(source, target) end end end
link(source, target)
click to toggle source
# File lib/mac_setup/symlink_installer.rb, line 133 def self.link(source, target) if File.exist?(target) if File.symlink?(target) existing_link = File.readlink(target) if existing_link == source.to_s MacSetup.log "Already linked. Skipping." else print "Replacing existing symlink at #{MacSetup.shorten_path(target)}. " puts "Originally linked to #{MacSetup.shorten_path(existing_link)}..." FileUtils.ln_sf(source, target) end else MacSetup.log "WARNING: File already exists at #{MacSetup.shorten_path(target)}. Skipping." end else FileUtils.ln_s(source, target) end end
run(config, _status)
click to toggle source
# File lib/mac_setup/symlink_installer.rb, line 95 def self.run(config, _status) install_symlinks(config) end