0

I am writing a diff parser for thunar but it is driving me mad.

The full idea is in it is simplest to select two files right click on them and select the option compare, then the result of diff between the two files is parsed to xmessage. The simplest works nicely, but I also want to compare files from different locations, so the idea is to copy one or two files and then run diff over them.

The great trouble is that I am not being able to format the output of xclip in order that diff could understand them (it reads the two lines as one filename)

What I tried:

selected="$(xclip -selection clipboard -o)"
diff -qyr "\"${selected//$'\n'/\" \"}\""

n=0
echo "$selected"| while read selection; do
    compare="$compare ${selection// /\ }"
    diff -qyr ${compare}
    n=$(($n+1))
done
echo "${compare[*]}"
echo xmessage diff: $(diff -qyr "${compare[0]}" "${compare[1]}") 

I solved this before hitting post using tail and head:

file1="$(echo "$selected"|head -n1)"
file2="$(echo "$selected"|tail -n1)"
xmessage "$(diff -qyr "$file1" "$file2")"

It was simpler than I thought, though why the more complicated solutions did not work?

Nic3500
  • 8,144
  • 10
  • 29
  • 40
  • I tried to format your question better, but it is still unclear what you are doing. A large section of your code is commented out, so...? Please edit your question and make it super clear. – Nic3500 Oct 24 '21 at 21:25
  • You can remove the postr if you will, since it was solved before posting, the only point of this post is if somebody can help out of it. I was looking something like ifs or xargs, which I suck at, but the simpler head/tail is far better for this case. Thanks for your comptrhension. Amd not thsat code is not commented – Lerian Acosenossa Oct 24 '21 at 22:24

0 Answers0