No announcement yet.

Diff From/To options within Eclipse IDE

  • Time
  • Show
Clear All
new posts

  • Diff From/To options within Eclipse IDE

    Hi guys,

    I wanted to have a "Diff From" and "Diff To" option within my Eclipse IDE (Linux), for occasions when I want to compare two open files within my IDE (ie, focus on one file, select "Diff From", focus on the other file and select "Diff To").

    I was pondering the following approach:
    • I'll add two "External Tools" commands that will call two bash-script files "bc_diff_from" and "bc_diff_to".
    • The "bc_diff_from" can save the file-path of the 1st file into a temp-file somewhere
    • The "bc_diff_to" can use the previously saved 'from' path and the current 'to' path to run: bcompare $(from_path) $(to_path)

    Is this the way to go? Or are there smarter/better ways to go about this?


    Because I was in a bit of a hurry for this, I've gone ahead and done it this way, will share the steps I've got, in-case others need this.
    1. Create the following two bash-scripts in your "~/bin" folder (which is hopefully already in your system's path, if not, add it).


      echo $1 > $HOME/bc.tmp


      FROM_PATH=`cat $HOME/bc.tmp`
      bcompare "$FROM_PATH" "$1"
      and then...
    2. In Eclipse, go to: "Run >> External Tools >> External Tools Configurations..."
    3. In the left-pane, click on the "Program" item, then click the "New launch configuration" button in the top-left corner.
    4. On the "Main" tab, set the following details:
      • Name: Diff From
      • Location: /home/gurce/bin/bc_diff_from (use your bin path instead)
      • Arguments: "${selected_resource_loc}" (quotes are essential - to handle paths with spaces)
    5. On the "Common" tab:
      • In the "Display in favourites menu", check the "External Tools" checkbox
    6. Click the "Apply" button to save these settings
    7. Click the "New launch configuration" button in the top-left corner again.
    8. On the "Main" tab, set the following details:
      • Name: Diff To
      • Location: /home/gurce/bin/bc_diff_to (use your bin path instead)
      • Arguments: "${selected_resource_loc}" (quotes are essential - to handle paths with spaces)
    9. On the "Common" tab:
      • In the "Display in favourites menu", check the "External Tools" checkbox
    10. Click the "Apply" button to save these settings

    You should now be able to see the "Diff From" and "Diff To" commands in the menus as below: (Run >> External Tools)

    If you are a keyboard jockey, you will notice that you can trigger these actions from the keyboard quite easily via:
    • Diff From: Alt+R, E, 1
    • Diff To: Alt+R, E, 2

    Usage Example

    So... Here's how I make use of this in my scenario. I have two files open in Eclipse that appear to have similar content:
    • I focus on my 1st file "egm_touchscreen.c" and type: "Alt+R, E, 1" (Diff From)
    • I focus on my 2nd file "itable_touchscreen.c" and type: "Alt+R, E, 2" (Diff To)

    Beyond Compare then will appear showing the two files compared side-by-side. While viewing this diff, you can modify either side to suit your merging needs, save your changes, close BC3, and then your changes will appear in Eclipse, very nice

    (Apologies for the large pics expanding the width of your frame. Thought it looked better than those tiny thumnails though)
    Last edited by Gurce; 08-Mar-2012, 07:12 PM. Reason: add pics to illustrate

  • #2

    The latest version of BC3 (3.3.4) supports a context menu in Linux. Would Eclipse have access to the standard context menu that your Explorer would have? If so, a "Select File as Left" and a "Compare to Left selected file" commands would already exist.

    If you haven't yet, you need to enable the context menu in the Tools menu -> Options dialog, in the Startup section. Once applied, you will need to Log Off/On to fully set the changes.
    Aaron P Scooter Software


    • #3
      Hi Aaron,

      Yep, I enjoy using the context menus for Linux, from within file-browsers such as dolphin and nautilus, but the goal I was aiming for was to have these diff'ing options available within the Eclipse IDE itself, and save me the trouble of leaving that environment, opening a file-browser, hunting down the files I want to diff and right-clicking them.

      Ie, just stay within the Eclipse IDE, which already had the files I was interested open. Click on the tab for one of the files and "Diff From", then click on the tab for the other file and "Diff To".

      I did have some screenshots do demonstrate how it flows, probably would make more sense if I uploaded them here, but your forum doesn't permit pic uploads Any chance this facility could be enabled for registered users of the forum?

      Anyway, the technique I mentioned above is working successfully, so I'm happy with it for now.


      • #4
        In the advanced mode, you can Manage Attachments and upload pictures.

        For my suggestion, I was curious if Eclipse allowed access to a standard context menu, similar to BC3's Explorer menu, which exposes all of the standard commands.
        Aaron P Scooter Software


        • #5
          Ah yep, sorry I thought the answer to your Q and forgot to write it I don't think there is any way to access the BC3 context menu additions from within Eclipse, as far as I know (but happy to be proven wrong by anybody and learn something).

          Although part of me wondered whether instead of my bash scripts, I could instead call whatever functionality is triggered whenever you "Select File as Left" and a "Compare to Left selected file".

          I did initially hunt around the bcompare command-line, hoping for some sort of "bcompare /select_left_file <path to my file name>" options, but didn't find any.

          Alrighty, I will append some pics into my initial post.


          • #6
            Take a look at Beyond CVS. It was last updated in 2010, so I don't know whether it still works, but it has a bunch of commands for opening BC comparisons from Eclipse.

            If you want to stick with your scripts, what you have is as about as good as you can get. All of the file manager add-ons do everything internally; they only call BC once they have a pair of files to compare. If you wanted to integrate with them a bit, they do store the left file's path in "~/.beyondcompare/left_file". If you use the same file you should be able to select one file in Eclipse and one in the file manager and compare them using either set of menu items.
            Zoë P Scooter Software