Grep command
May 7, 2018

How to Add a Grep Command to Search Your Helix Core Depot


If you’ve ever found yourself searching for lines of code in your Helix Core (P4D) depot, you’re probably familiar with the p4 grep command. It's exactly what you’d expect from a grep command – an easy way to search for regular expressions.

There’s an extension point in Helix Visual Client (P4V) in the form of Custom Tools. Custom Tools are the glue between selecting items in P4V and passing them as arguments to external programs. This lets you create menu items and tighten your workflow experience without ever leaving the application.

How to Add a P4 Grep Command as a Custom Tool in P4V

If you use P4V on Linux, you can have the p4 grep functionality at your fingertips by adding it as a Custom Tool. Let’s go through the steps.

  1. Install the Helix Command-Line Client (P4) on your local machine.
  2. In P4V, click on “Tools" then "Manage Custom Tools”
  3. In the Manage Custom Tools dialog, click on “New" then "Tool”
  4. Enter the information as follows:
    • Name: p4 grep
    • Application: /path/to/p4
    • Arguments: grep -n -e $D %D
  5. Check the ​“Run tool in terminal window” option
  6. Check the “Prompt user for arguments” option
    •  ​Description:​ File pattern
Configuring a Custom Tool with grep
This is what the window should look like when you’re configuring a Custom Tool.

That’s it.

Using the P4 Grep Command

Now, when you right click a file in your workspace directory, there will be a new menu item named “p4 grep.”

New menu item named “p4 grep”

Clicking on it will bring up a prompt for the file pattern.

File prompt for p4 grep command

After you input the string of interest, a new window will reveal the results of the command.

Results of the p4 grep command

Searching for Content in Your Perforce Depot

Using the p4 grep command is a great way to search for content in a Helix Core depot. If you don’t want to use command line utilities, there are many ways you can extend P4V using Custom Tools. This is an easy way to add functionality power without leaving the comfort of P4V.