Created
December 16, 2019 11:16
-
-
Save seasonedgeek/785c224a4ab1dcc679f748e1ac76c04d to your computer and use it in GitHub Desktop.
Diving into FileUtils: Update various dotfiles' symbolic links after changing original directory.
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
require "FileUtils" | |
# Update various dotfiles' symbolic links following directory change. | |
# Experimentation involving a deep dive into the Ruby 2.6.5 API. | |
module RemakeSymbolicLinks | |
USR = '/Users/tstewart' | |
CFG1 = 'zsh/configs' | |
CFG2 = 'zsh/configs/post' | |
TBOT = "#{USR}/Documents/Scripts/dotfiles/thoughtbot" | |
# Destorys & creates symbolic links of dotfiles for zsh configuration. | |
def for_zsh_config | |
target_path = "#{TBOT}/#{CFG1}" | |
link_path = "#{USR}/.#{CFG1}" | |
# named files to replace | |
file_names = %w[editor history homebrew keybindings options prompt] | |
begin | |
file_names.each do |file_name| | |
linked_file = "#{link_path}/#{file_name}.zsh" | |
target_file = "#{target_path}/#{file_name}.zsh" | |
if File.exist? linked_file | |
FileUtils.remove_file linked_file | |
FileUtils.ln_s target_file, linked_file, verbose: true | |
else | |
puts "ERROR - #{linked_file} does not exist!" | |
end | |
end | |
rescue Errno::ENOENT => e | |
puts e.message | |
end | |
end | |
# Destorys & creates symbolic links of dotfiles for post zsh configuration. | |
def for_post_zsh_config | |
target_post_path = "#{TBOT}/#{CFG2}" | |
link_post_path = "#{USR}/.#{CFG2}" | |
# named files to replace | |
post_file_names = %w[completion path] | |
begin | |
post_file_names.each do |post_file_name| | |
link_posted_file = "#{link_post_path}/#{post_file_name}.zsh" | |
target_post_file = "#{target_post_path}/#{post_file_name}.zsh" | |
if File.exist? link_posted_file | |
FileUtils.remove_file link_posted_file | |
FileUtils.ln_s target_post_file, link_posted_file, verbose: true | |
else | |
puts "ERROR - #{link_posted_file} does not exist!" | |
end | |
end | |
rescue Errno::ENOENT => e | |
puts e.message | |
end | |
end | |
end | |
# Helper | |
class Symbolic | |
include RemakeSymbolicLinks | |
end | |
symbolic = Symbolic.new | |
symbolic.for_zsh_config | |
symbolic.for_post_zsh_config |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment