Configuring custom tools

You can add commands and folders to the Tools menu. The tools can then be accessed from the Tools menu in P4V and optionally from context menus. For each custom tool, you can also create a shortcut. You can export your custom tool definitions to a file from which other P4V users can import them.

Environment considerations

P4V launches the specified custom tool in an external process. Perforce settings are exported to the external process as follows: the P4PORT, P4USER, P4CLIENT and P4CHARSET settings in effect for the P4V connection are exported to the external process, plus any other Perforce settings present in the environment in which P4V is running, including command-line arguments specified when P4V was launched and global settings (on Windows machines, settings configured using the p4 set -s command).

If the P4CONFIG environment variable is set, the tool recognizes any P4CONFIG files present in the file hierarchy on which it is operating. Settings in P4CONFIG files override settings in the environment. To ensure that P4CONFIG settings do not override environment settings, select Ignore P4CONFIG files. (For details about config files, refer to the P4 User’s Guide.) If you are passing arguments to a custom tool, select Ignore P4CONFIG files to ensure that the server settings used by the custom tool correspond to the values that are passed.

On a Mac, custom tools are not launched from a shell by default. For tools that must recognize P4CONFIG settings, create a script that launches a shell before invoking the tool, or define P4CONFIG globally (for example, in /etc/profile, /etc/profile.local, or /etc/csh.login). To spawn a shell using Bourne shell, issue the #!/bin/sh command. For the C shell, issue the #!/bin/tcsh command.

If you need to keep a tool running or launch another application, run it in the background and exit the shell or process that was launched by the custom tool. This approach ensures that you do not block another tool and that the application will remain open when you exit P4V.

Add custom tools

To add custom tools to P4V:

  1. Choose Tools > Manage Custom Tools​.

    The Manage Custom Tools dialog is displayed.

  2. Click New and choose Tool…​.

    The Add Custom Tool dialog is displayed.

    Note

    In P4Admin, the Add Local Tool dialog is displayed.

  3. In the Name field, enter the name of the menu item you want to appear on the Tools menu.
  4. Use the Placement field to define where you want the tool to appear in the Tools menu. Select the Add to applicable context menus check box if you want the new tool to be available in P4V context menus.
  5. Specify the application that you want to associate with this command in the Application field. To browse to the application, click Browse. (You can drag and drop the application from an Explorer or Finder window to the Application field.)

    Important

    To define tools that issue p4 commands, specify p4 in the Application field and the command and desired arguments (for example, fix -c %c job000001) in the Arguments field. Specify the application and arguments separately in the fields provided.

  6. In the Arguments field, enter command arguments using the specifiers listed in the following table.

    Note

    Some arguments have an uppercase and lowercase form. To run the tool once, submitting all values together, specify the uppercase argument. To run the tool once for each value, specify the lowercase form.

    %a

    Selected label

    %b

    Selected branch

    %C, %c

    Selected changelists

    %D, %d

    Selected files or folders (depot syntax used for depot files)

    %F, %f

    Selected files (workspace syntax used for depot files)

    %i

    Selected workspace specifications

    %J, %j

    Selected jobs

    %O, %o

    Depends on which pane has focus:

    • When left pane has focus, selected checked out files.
    • When right pane has focus, all checked out files.

    %P, %p

    Selected pending changelists

    %S, %s

    Selected submitted changelists

    %t

    Selected stream

    %u

    Selected user

    $c

    Current workspace specification

    $p

    Current port

    $r

    Current client workspace root

    $u

    Current user

    $D

    Arguments from prompt dialog

    $%

    Literal '%' character

    $$

    Literal '$' character

    Notes about arguments:

    • Arguments must be separated by white space.
    • To specify values containing spaces, double-quote them. For example:

      "C:\Program Files\scripts\changelistreport.pl" %p
    • You can specify only one % argument per tool definition.
    • Uppercase specifiers send values to the command as a group. Lowercase specifiers run the command once for each value.

      For example: mycommand %F runs mycommand arg1 arg2 arg3 and mycommand %f runs mycommand arg1; mycommand arg2; mycommand arg3.

    • If your custom tool includes arguments from a prompt dialog ($D), you must warn users to avoid the "&" character when they enter a string value in your custom tool prompt. The "&" value is a special character.
  7. In the Start in field, specify the directory where you want the command to execute. You can specify the directory using:

    • operating system syntax (for example: C:\tmp, or /tmp), or
    • %f, which uses the directory of the selected file.
      If you specify %f, omit any other values. For example, %f\temp is invalid.
  8. To execute the application in a terminal window that displays standard input and output, select Run tool in terminal window.
  9. To enable users to enter arguments after they choose the custom tool menu item, select Prompt user for arguments and enter a description of the required arguments in the Description field. To enable users to browse when prompted, select Add file browser to prompt dialog.
  10. To refresh P4V after the tool application finishes running, select Refresh P4V upon completion.
  11. To save your entries, click OK.
  12. To add a shortcut for the tool, double-click the Shortcut column and enter the desired key combination.

    If a shortcut is reserved or already in use, P4V displays a warning message.

  13. To exit the Manage Custom Tools dialog, click OK.

Import and export tools

You can export the tools you’ve defined to an XML file that other P4V users can import. Likewise, you can import tools that other P4V users have created.

To import tools:

  1. Choose Tools > Manage Custom Tools…​

    The Manage Custom Tools dialog is displayed.

  2. Click Import tools…​

    P4V displays the Read Custom Tools from a File dialog.

  3. Enter the file name or browse to the file and click Open.

    The Import Preview dialog is displayed.

  4. Click Import.

    The tool definitions are imported.

To export tools:

  1. Choose Tools > Manage Custom Tools…​

    The Manage Custom Tools dialog is displayed.

  2. Click Export tools…​

    The Export Preview dialog is displayed.

  3. Select the tools you want to export and click Export.

    The Save Custom Tools to a File dialog is displayed.

  4. Enter a file name and browse to the location where you want to save the export file and click OK.
Note

On Windows, if a tool does not run, verify that the files that it opens have their extensions mapped to the required application.