Skip to content

Instantly share code, notes, and snippets.

@0x4a
Created January 16, 2014 03:12
Show Gist options
  • Save 0x4a/8449228 to your computer and use it in GitHub Desktop.
Save 0x4a/8449228 to your computer and use it in GitHub Desktop.
#ahk #frontend to gnu #diff #tool
#NoEnv
#SingleInstance, force
SetWorkingDir %A_ScriptDir%
FileEncoding UTF-8
args = %0%
a_old = %1%
a_new = %2%
global timestamp, diffout
global log := SubStr(A_ScriptName, 1, -4) ".log"
SplitPath, a_new,, savedir,, basename
diffout := savedir "\" basename ".diff"
FormatTime, timestamp, , dd.MM. HH:mm:ss tt
diffpath = "c:\Program Files (x86)\GnuWin32\bin\diff.exe"
diffargs = -U3 -Bib
if (args <> 2) ; two arguments
logMessage("wrong number of arguments: " . args . " found, 2 expected", "error")
else if (!FileExist(a_old)) ; two files
logMessage("file not found: " . a_old, "error")
else if (!FileExist(a_new))
logMessage("file not found: " . a_new, "error")
logMessage("--- " . a_old . "`t`t+++ " . a_new, "comp")
RunWait, %comspec% /c %diffpath% %diffargs% %a_old% %a_new% > %diffout%, , Hide UseErrorLevel
if ErrorLevel = ERROR
logMessage("Diff could not be launched from " . diffpath, "error")
else
logMessage(">>> " . diffout, "save")
exit
logMessage(text, mode = "info") {
StringUpper, mode, mode
FileAppend, [%timestamp%] [%mode%] %text%`n, %log%
if mode = ERROR
{
Msgbox,262208 , %mode%, %text%`n`n`nUsage:`n%A_ScriptName% <oldfile> <newfile>
Exit
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment