Sha256: cb21bef5924d76f45ece138162e17759a647999624290a93c7fd4b52c11151d5
Contents?: true
Size: 1.9 KB
Versions: 27
Compression:
Stored size: 1.9 KB
Contents
#!/usr/bin/env ruby require 'pathname' require 'tins/xt' require 'fileutils' include FileUtils::Verbose require 'utils' require 'term/ansicolor' include Term::ANSIColor $config = Utils::ConfigFile.new $config.configure_from_paths def local_path(path) Pathname.new(path).expand_path.relative_path_from( Pathname.new(?.).expand_path ).to_s end def diff_dir `diff -rq #{$src.inspect} #{$dst.inspect}` end def ask?(prompt:) print prompt gets.chomp end $src = ARGV.shift or fail "need source directory as first argument" $src = local_path $src $dst = ARGV.shift || ?. $dst = local_path $dst puts diff_dir diff_dir.each_line do |line| case line when /^Only in (.*?): (.*?)$/ s, d = $~.captures sd = local_path(s) s = local_path(File.join(sd, d)) $config.sync_dir.skip?(s) and next dd = [ $src, $dst ].find { _1 != sd } d = local_path(File.join(dd, d)) if File.file?(s) and File.ascii?(s) puts color(214, File.read(s)) end puts " Only found in #{s.inspect} ".center(Tins::Terminal.cols, ?*) puts <<~end (C)opy #{s.inspect} to #{d.inspect} (E)dit #{s.inspect} (D)elete #{s.inspect} (S)kip (Q)uit end case ask?(prompt: 'action? ') when /\Ac/i cp s, d when /\Ae/i system "vim #{s.inspect}" redo when /\Ad/i rm s when /\Aq/i exit end when /^Files (.*?) and (.*?) differ$/ s, d = $~.captures s = local_path(s) $config.sync_dir.skip?(s) and next d = local_path(d) puts `diff --color=always -u #{s.inspect} #{d.inspect}` puts " Difference found #{s.inspect} #{d.inspect} ".center(Tins::Terminal.cols, ?*) puts <<~end (V)imdiff (S)kip (Q)uit end case ask?(prompt: 'action? ') when /\Av/i system "vimdiff #{s.inspect} #{d.inspect}" when /\Aq/i exit else next end redo end rescue Interrupt exit end
Version data entries
27 entries across 27 versions & 1 rubygems