Editing specs and workspace alias files

Advanced uses of command aliases include the following.

Editing specifications

The p4subst special operator allows you to edit specs. It is roughly analogous to doing the following in a shell pipeline:

| sed 's/regular_expression/literal/g'

The p4subst special operator should normally be used in an alias as fellows:

something > $(output) &&
p4subst "regular expression" "literal replacement" < $(output) > $(result) &&
something else < $(result)

As an example, consider the string substitution in the following alias:

newChange $(desc) = change -o > $(chg) &&
                   p4subst "$(LT)enter.*$(GT)" $(desc) < $(chg) > $(chg2) &&
                   change -i < $(chg2)

The alias replaces the default change description with the argument provided to p4 newChange description.

Creating alias files for each workspace

To create an alias file for each workspace, add the following line to your P4CONFIG file:

P4ALIASES=$configdir/p4aliases.txt

Since your P4CONFIG file is found wherever you might be working and that location is known by the special $configdir value, you can have a P4ALIASES file that is specific to this workspace and which is conveniently found no matter where you are in that workspace.