WinMerge Macro

Here you can discuss any topic concerning Far macro commands.
Post Reply
gene.pavlovsky
Posts: 157
Joined: Tue 11 Aug, 2015 16:53
Has thanked: 11 times

WinMerge Macro

Post by gene.pavlovsky » Wed 12 Aug, 2015 18:12

Provides two shortcuts for WinMerge:
- Compare the selected files or the current folders (1 items selected on each panel - compare those, 2 items selected on the active panel - compare those, otherwise compare active panel folder and passive panel folder)
- Compare the current files/folders (compare active panel file/folder with passive panel file/folder)
Runs WinMerge from the command line, can be easily modified to use another GUI merge tool.

Code: Select all

local function winmerge(File1, File2, swap)
  if swap then
    Tmp = File2
    File2 = File1
    File1 = Tmp
  end
  Keys("Esc")
  Far.DisableHistory(0)
  print('winmerge "' .. File1 .. '" "' .. File2 .. '"')
  Keys("Enter")
end

Macro {
  area="Shell"; key="CtrlM"; description="WinMerge: Compare the selected files or the current folders";
  action = function()
    if APanel.SelCount == 1 then
      File1 = APanel.Path .."\\" .. panel.GetSelectedPanelItem(nil, 1, 1).FileName
      if PPanel.SelCount == 1 then
        File2 = PPanel.Path .."\\" .. panel.GetSelectedPanelItem(nil, 0, 1).FileName
      else
        File2 = PPanel.Path .."\\" .. panel.GetSelectedPanelItem(nil, 1, 1).FileName
      end
      winmerge(File1, File2, not APanel.Left)
    elseif APanel.SelCount == 2 then
      File1 = APanel.Path .."\\" .. panel.GetSelectedPanelItem(nil, 1, 1).FileName
      File2 = APanel.Path .."\\" .. panel.GetSelectedPanelItem(nil, 1, 2).FileName
      winmerge(File1, File2, false)
    else
      winmerge(APanel.Path, PPanel.Path, not APanel.Left)
    end;
  end;
}

Macro {
  area="Shell"; key="CtrlShiftM"; description="WinMerge: Compare the current files/folders";
  action = function()
    File1 = panel.GetPanelDirectory(nil, 0).Name .. "\\" .. panel.GetCurrentPanelItem(nil, 0).FileName
    File2 = panel.GetPanelDirectory(nil, 1).Name .. "\\" .. panel.GetCurrentPanelItem(nil, 1).FileName
    winmerge(File1, File2, not APanel.Left)
  end;
}

gene.pavlovsky
Posts: 157
Joined: Tue 11 Aug, 2015 16:53
Has thanked: 11 times

WinMerge Macro

Post by gene.pavlovsky » Wed 12 Aug, 2015 18:14

Based on VisualCompare macro posted by cyberwolf:
viewtopic.php?t=7905

gene.pavlovsky
Posts: 157
Joined: Tue 11 Aug, 2015 16:53
Has thanked: 11 times

WinMerge Macro

Post by gene.pavlovsky » Wed 12 Aug, 2015 18:23

Little fix. Can't figure out how to edit my own post!

Code: Select all

local merge_tool='winmerge'

local function winmerge(File1, File2, swap)
	Keys("Esc")
	Far.DisableHistory(0)
	if (swap) then
		print(merge_tool .. ' "' .. File2 .. '" "' .. File1 .. '"')
	else          
		print(merge_tool .. ' "' .. File1 .. '" "' .. File2 .. '"')
	end	
	Keys("Enter")
end

Macro {
	area="Shell"; key="CtrlM"; description="WinMerge: Compare the selected files or the current folders";
	action = function()
	  if APanel.SelCount == 1 then
	    File1 = APanel.Path .."\\" .. panel.GetSelectedPanelItem(nil, 1, 1).FileName
	    if PPanel.SelCount == 1 then
	      File2 = PPanel.Path .."\\" .. panel.GetSelectedPanelItem(nil, 0, 1).FileName
	    else
	      File2 = PPanel.Path .."\\" .. panel.GetSelectedPanelItem(nil, 1, 1).FileName
	    end
	    winmerge(File1, File2, not APanel.Left)
	  elseif APanel.SelCount == 2 then
      File1 = APanel.Path .."\\" .. panel.GetSelectedPanelItem(nil, 1, 1).FileName
      File2 = APanel.Path .."\\" .. panel.GetSelectedPanelItem(nil, 1, 2).FileName
      winmerge(File1, File2, false)
    else
    	winmerge(APanel.Path, PPanel.Path, not APanel.Left)
	  end;
	end;
}

Macro {
	area="Shell"; key="CtrlShiftM"; description="WinMerge: Compare the current files/folders";
	action = function()
	  File1 = panel.GetPanelDirectory(nil, 1).Name .. "\\" .. panel.GetCurrentPanelItem(nil, 1).FileName
	  File2 = panel.GetPanelDirectory(nil, 0).Name .. "\\" .. panel.GetCurrentPanelItem(nil, 0).FileName
	  winmerge(File1, File2, not APanel.Left)
	end;
}

2useven10
Posts: 2953
Joined: Mon 07 Sep, 2009 10:40
Has thanked: 2 times
Been thanked: 77 times

WinMerge Macro

Post by 2useven10 » Wed 12 Aug, 2015 18:58

gene.pavlovsky wrote:Little fix. Can't figure out how to edit my own post!
It will be possible after 5 (or 6) posts.

pepak
Posts: 312
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 1 time
Been thanked: 9 times

WinMerge Macro

Post by pepak » Thu 13 Aug, 2015 06:45

I use a similar task: Run WinMerge on selected file on the active panel and the same-named file on the passive panel. So it is much more limited than your script, but much simpler, too - it just needs this command in the user menu: winmerge "!.!" "!#!\!^!.!"

Note that your shortcut CTRL+M conflicts with native useful functionality - restore selection.

gene.pavlovsky
Posts: 157
Joined: Tue 11 Aug, 2015 16:53
Has thanked: 11 times

WinMerge Macro

Post by gene.pavlovsky » Mon 17 Aug, 2015 14:11

Wow, used FAR for over 15 years and never knew about CTRL+M! Thanks! I'll change the shortcut to something else...

Post Reply

Return to “Macro Commands Discussions”

Who is online

Users browsing this forum: No registered users and 1 guest