WinMerge Macro

Here you can discuss any topic concerning Far macro commands.
Post Reply
gene.pavlovsky
Posts: 170
Joined: Tue 16 Feb, 2010 17:55
Location: Luxembourg
Has thanked: 11 times
Been thanked: 9 times
Contact:

WinMerge Macro

Post by gene.pavlovsky »

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: 170
Joined: Tue 16 Feb, 2010 17:55
Location: Luxembourg
Has thanked: 11 times
Been thanked: 9 times
Contact:

WinMerge Macro

Post by gene.pavlovsky »

Based on VisualCompare macro posted by cyberwolf:
http://forum.farmanager.com/viewtopic.php?t=7905
gene.pavlovsky
Posts: 170
Joined: Tue 16 Feb, 2010 17:55
Location: Luxembourg
Has thanked: 11 times
Been thanked: 9 times
Contact:

WinMerge Macro

Post by gene.pavlovsky »

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: 5192
Joined: Mon 07 Sep, 2009 10:40
Has thanked: 18 times
Been thanked: 309 times

WinMerge Macro

Post by 2useven10 »

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: 604
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 17 times
Been thanked: 54 times

WinMerge Macro

Post by pepak »

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: 170
Joined: Tue 16 Feb, 2010 17:55
Location: Luxembourg
Has thanked: 11 times
Been thanked: 9 times
Contact:

WinMerge Macro

Post by gene.pavlovsky »

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”