Saturday, December 19, 2020

CopyQ - Quick diff texts

TL;DR

In short, you can use the power of CopyQ commands in order to quickly compare any two pieces of text - just copy the texts into the clipboard and run the Diff Latest Items command on them. As always, simply follow the installation instructions in order to install the command into your CopyQ instance.

As mentioned in the documentation page, you will also need a compare tool that can be invoked by the CopyQ command in order to do the actual comparison. The last step is, possibly, to modify a part of the command's code. This part looks like the following at the time of writing:

// Choose your favorite diff tool (leave just one execute(...) uncommented):

// === Beyond Compare ===
// reference: https://www.scootersoftware.com/v4help/command_line_reference.html
execute('bcompare', name1, name2)

// === WinMerge ===
// reference: https://manual.winmerge.org/en/Command_line.html
// execute('winmergeu', '/e', '/x', '/u', '/fl', '/dl', 'item1', '/dr', 'item2', name1, name2)

Note: In order to work, the program passed to the execute() command must be on the system PATH, otherwise a full path to the program needs to be specified.

Story of the Diff Latest Items command

I don't know how you, but I pretty much hate doing something that a computer can do for me instead. In regards of this post, it is finding out differences in texts. It might be the case of comparing similarly looking methods in a source code, or for example similar paragraphs found on different web pages.

Of course, one can use many different tools to do the comparison, but they usually require you to firstly have files created that are going to be compared.1 So, I was looking for a quick and universal solution. And once you get familiar with CopyQ, creating a simple CopyQ command just for that is the next logical step, and that is how the Diff Latest Items command got created. Well, I'm not the original author of it though. :)

I was playing with this idea in my head for several weeks and just on the weekend when I started with implementation, I searched for an example of how to create a temporary file from CopyQ (so that it can be fed to an external comparison tool). And instead of an example, I found this ready-to-use script that was created just a few days before! So at least I improved its documentation and also added support for my favorite tool WinMerge, job done. :)

Conclusion

And what about you? Do you have some other tricks of how to compare text chunks? Or have you also found this CopyQ's command useful? Don't hesitate to let all know in the comments. :)


1 If you use Eclipse IDE, for example, and you are lucky enough to come across the AnyEdit Tools plugin, you can e. g. compare a part of an opened file with clipboard contents pretty easily. Yet, this still requires some clicking "here and there" and we also know that startup times of IDEs like Eclipse are not the best. ;)