Perforce Public Knowledge Base - Command line P4Merge on Mac OS X
Reset Search
 

 

Article

Command line P4Merge on Mac OS X

« Go Back

Information

 
Problem

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.

  1. 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 $*
  2. To use the script, you must make it executable. Enter the command:

    chmod +x mymerge.sh
  3. Place mymerge.sh into the /usr/bin directory (or any directory set in 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 /path/file_1 /path/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.

 

An alternative to using shell script is to add an "alias" to the shell profile. For example, for the bash shell add the following line to the .bashrc file in the home directory:

alias p4merge='/Applications/p4merge.app/Contents/MacOS/p4merge

Now running p4merge against to relative files in the current working directory will work in the form of:

p4merge file1 file2
Related Links

Feedback

 

Was this article helpful?


   

Feedback

Please tell us how we can make this article more useful.

Characters Remaining: 255