rewored to account for platform folders

This commit is contained in:
Gene Liverman 2017-05-07 22:00:34 -07:00
parent 7ea77f0740
commit 8b465e78f1

View file

@ -4,8 +4,15 @@ require 'tty-command'
require 'tty-file' require 'tty-file'
require 'tty-prompt' require 'tty-prompt'
# cmd = TTY::Command.new
prompt = TTY::Prompt.new(help_color: :magenta) prompt = TTY::Prompt.new(help_color: :magenta)
@home = File.expand_path('~')
@dotroot = File.dirname(File.dirname(File.expand_path($PROGRAM_NAME)))
@excludes = %w[mac nix]
@files_copy = Dir.glob("#{@dotroot}/copy/*")
@files_link = Dir.glob("#{@dotroot}/link/*")
if OS.mac? if OS.mac?
stdout, _stderr, _status = Open3.capture3('sw_vers -productVersion') stdout, _stderr, _status = Open3.capture3('sw_vers -productVersion')
if Integer(stdout.strip.split('.')[0]) == 10 if Integer(stdout.strip.split('.')[0]) == 10
@ -14,33 +21,36 @@ if OS.mac?
else else
puts "It seems you are on OX X #{stdout.strip}" puts "It seems you are on OX X #{stdout.strip}"
end end
elsif Integer(stdout.strip.split('.')[0]) < 10 elsif Integer(stdout.strip.split('.')[0]) < 10
puts "Wow... you're sure running an old os (#{stdout.strip} to be exact)" puts "Wow... you're sure running an old os (#{stdout.strip} to be exact)"
else else
abort("It seems you are on a Mac but I don't know what to do on \ abort("It seems you are on a Mac but I don't know what to do on \
v#{stdout.strip}") v#{stdout.strip}")
end end
@files_copy.concat Dir.glob("#{@dotroot}/copy/mac/*")
@files_link.concat Dir.glob("#{@dotroot}/link/mac/*")
elsif OS.liux? elsif OS.liux?
puts 'It seems you are on Linux' puts 'It seems you are on Linux'
@files_copy.concat Dir.glob("#{@dotroot}/copy/nix/*")
@files_link.concat Dir.glob("#{@dotroot}/link/nix/*")
elsif OS.windows? elsif OS.windows?
puts 'It seems you are on Windows' puts 'It seems you are on Windows'
else else
abort("I'm not sure what to do with this OS...") abort("I'm not sure what to do with this OS...")
end end
@home = File.expand_path('~')
@dotroot = File.dirname(File.dirname(File.expand_path($PROGRAM_NAME)))
@excludes = %w[mac nix]
task = prompt.select('What would you like to do?', %w[copy link]) task = prompt.select('What would you like to do?', %w[copy link])
case task case task
when 'copy' when 'copy'
files = Dir.glob("#{@dotroot}/copy/*")
if prompt.yes?('Are you sure you want to copy these files?') if prompt.yes?('Are you sure you want to copy these files?')
puts 'Copying files...' puts 'Copying files...'
files.each do |file| @files_copy.each do |file|
unless @excludes.include?(File.basename(file)) unless @excludes.include?(File.basename(file))
puts "Copying #{file} to #{@home}/.#{File.basename(file)}" puts "Copying #{file} to #{@home}/.#{File.basename(file)}"
end end
@ -50,12 +60,10 @@ when 'copy'
end end
when 'link' when 'link'
files = Dir.glob("#{@dotroot}/link/*")
if prompt.yes?('Shall we continue?') if prompt.yes?('Shall we continue?')
puts 'Creating symlinks...' puts 'Creating symlinks...'
files.each do |file| @files_link.each do |file|
unless @excludes.include?(File.basename(file)) unless @excludes.include?(File.basename(file))
puts "Linking #{@home}/.#{File.basename(file)} to #{file}" puts "Linking #{@home}/.#{File.basename(file)} to #{file}"
end end