mirror of
https://github.com/genebean/dots.git
synced 2026-03-27 01:17:42 -04:00
got linking working
This commit is contained in:
parent
77fce59b08
commit
6e4d63fd03
3 changed files with 50 additions and 8 deletions
32
bin/dotutils.rb
Normal file
32
bin/dotutils.rb
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
def existing_symlink(source, destination)
|
||||
return if File.readlink(destination).eql?(source)
|
||||
# rubocop:disable Metrics/LineLength
|
||||
if @prompt.yes?("#{destination} currently points to #{File.readlink(destination)}, do you want point it at #{source}?")
|
||||
File.unlink(destination)
|
||||
puts "Linking #{destination} to #{source}"
|
||||
File.symlink(source, destination)
|
||||
puts 'link replaced'
|
||||
else
|
||||
puts "#{destination} is unchanged"
|
||||
end
|
||||
# rubocop:enable Metrics/LineLength
|
||||
end
|
||||
|
||||
def rename_file(source, destination)
|
||||
puts "#{destination} exists, renaming to #{destination}.predots"
|
||||
File.rename(destination, "#{destination}.predots")
|
||||
puts "Linking #{destination} to #{source}"
|
||||
File.symlink(source, destination)
|
||||
end
|
||||
|
||||
def link_file(source, destination)
|
||||
if File.exist?(destination) && File.symlink?(destination)
|
||||
existing_symlink(source, destination)
|
||||
elsif File.exist?(destination)
|
||||
# this catches anything that is not a symlink
|
||||
rename_file(source, destination)
|
||||
else
|
||||
puts "Linking #{destination} to #{source}"
|
||||
File.symlink(source, destination)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue