yousseb / meld

Meld for macOS

Home Page:https://yousseb.github.io/meld/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Offer formatting option

iwalucas opened this issue · comments

I use meld a lot to compare JSON files, and its always an extra step for me to format that on some external tool, before pasting it into meld.
Any chance of adding some basic formatting options?

Multiple people ran into this issue.
What I did to resolve it is to make a temp copy of each file which i "prettified" first, and then run meld.
Just place this in "/usr/local/bin/meldjson" and make it executable ($ chmod u+x /usr/local/bin/meldjson).
Note sure how safe this is, but it does the job!
Of course you could also create this script as a bash script...

#!/bin/bash
#Pretty meld: prettify JSON files and then execute meld.

script="
import json
import os

def clean(filename):
    filename_out = '/tmp/' + os.path.basename(filename)
    with open(filename) as f:
        data = json.load(f)
    with open(filename_out, 'w') as f:
        json.dump(data, f, indent=4, sort_keys=True)
    return filename_out
    
filename_tmp_1 = clean('$1')
filename_tmp_2 = clean('$2')
os.system('/usr/bin/meld ' + filename_tmp_1 + ' ' + filename_tmp_2)
os.system('rm ' + filename_tmp_1 + ' ' + filename_tmp_2)
"

python -c "$script"