Last active
October 25, 2021 14:44
-
-
Save gregawoods/5358193 to your computer and use it in GitHub Desktop.
Show the diff between two folders in Kaleidoscope for OS X. While you can do this out of the box with the `ksdiff` command line tool it does not dive into subdirectories like I wanted. Usage: ksdiffdir.rb path/to/a path/to/b
This file contains hidden or 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
#!/usr/bin/env ruby | |
# Usage: | |
# ksdiffdir.rb /path/to/a /path/to/b | |
FOLDER_A = ARGV[0] | |
FOLDER_B = ARGV[1] | |
def build_file_list(dir_path) | |
Dir.glob("#{dir_path}/**/*").select{ |f| File.file?(f) }.collect{ |f| f.gsub("#{dir_path}", '') } | |
end | |
def ks_diff(base, left, right) | |
left ||= "/dev/null" | |
right ||= "/dev/null" | |
`ksdiff --partial-changeset --relative-path "#{base}" -- "#{left}" "#{right}"` | |
end | |
change_list = [] | |
add_list = [] | |
remove_list = [] | |
if File.exists?(FOLDER_A) && File.exists?(FOLDER_B) | |
file_list_a = build_file_list(FOLDER_A) | |
file_list_b = build_file_list(FOLDER_B) | |
file_list_a.each do |f| | |
if file_list_b.include?(f) | |
file_list_b.delete(f) | |
if File.read(File.join(FOLDER_A, f)) != File.read(File.join(FOLDER_B, f)) | |
change_list << f | |
end | |
else | |
remove_list << f | |
end | |
end | |
add_list += file_list_b | |
change_list.each do |f| | |
ks_diff(f, File.join(FOLDER_A, f), File.join(FOLDER_B, f)) | |
end | |
add_list.each do |f| | |
ks_diff(f, nil, File.join(FOLDER_B, f)) | |
end | |
remove_list.each do |f| | |
ks_diff(f, File.join(FOLDER_A, f), nil) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment