Command line P4Merge on Mac OS X
TASK
Using P4Merge from the Mac OS X command line
Using a third-party diff/merge tool from the Mac OS X command line
SOLUTION
There is a small helper application embedded in the P4Merge application that enables running P4Merge from the OS X command line. We refer to this helper application (launchp4merge) as a "shim".
The shim is a part of the P4Merge application bundle and should not be removed or renamed. To use the shim you must write a small shell script.
-
Using a text editor, create a file called mymerge.sh containing the following two lines:
#!/bin/sh <path to P4Merge>/p4merge.app/Contents/Resources/launchp4merge $*
Replace <path to P4Merge> with the real path to the P4Merge application. If you placed P4Merge in the standard Applications directory, the script will look like this:
#!/bin/sh /Applications/p4merge.app/Contents/Resources/launchp4merge $*
-
To use the script, you must make it executable. Enter the command:
chmod +x mymerge.sh
- Place mymerge.sh into the /usr/bin directory (or any directory set by your $PATH environment variable).
After these steps are completed, you can run launchp4merge from the command line. For example, to diff two files, enter the command:
mymerge.sh file_1 file_2
You can pass command line options to launchp4merge as well. To see a list of options, enter mymerge.sh -h and a listing of launchp4merge command options is displayed in the Terminal window.
You can start as many shim processes as you require. Each launchp4merge process is attached to the resulting window in the P4Merge application. When the window is closed, the process terminates automatically.
To use a third-party diff/merge application, you would use an approach similar to the above example. For example, to use "kdiff" as your diff utility, you would create a file called kdiff.sh containing the following lines:
#!/bin/sh exec /Applications/kdiff3.app/Contents/MacOS/kdiff3 "$1" "$2"
Then proceed with steps 2 and 3 as in the first example, substituting kdiff.sh as the filename.
