Setting Perforce (P4) on Unix/Mac easier.
On Mac and Unix command line clients, you know, or learn shortly, that you can't "export" system variables from a script. But if you work on several projects, you will soon get tired of exporting various P4 required variables.
You can use the P4CONFIG to group several of these P4 variables together. But you still have to type
export P4CONFIG=<SOMEFILE>
Here is a more structured way....
If you do this below when it returns, you won't have any more aliases then when you started. Unless you put it in your .profile file!
export P4CONFDIR=~/p4config
# This sets aliases for P4
for P4C in `find $P4CONFDIR -type f`
do
alias p4c`basename -s .P4CONFIG $P4C`='export P4CONFIG='$P4C
done
# End of setting aliases for P4.
Now, what does this do? Well if for each P4 client you have you create a "client.P4CONFIG" file in the $P4CONFDIR, you can create a simple alias to change to your different clients.
The ".P4CONFIG" extension is hard coded above, something that could be improved!
I put these files in /Users/phecht/p4config. (That is what I have P4CONFDIR set to above.)
/Users/phecht/p4config/main.P4CONFIG
/Users/phecht/p4config/proda.P4CONFIG
After I start a new terminal window I get this:
phecht$ alias
alias ll='ls -l'
alias p4cmain='export P4CONFIG=/Users/phecht/p4config/main.P4CONFIG'
alias p4cproda='export P4CONFIG=/Users/phecht/p4config/proda.P4CONFIG'
This allows me to type:
p4cmain
instead of
export P4CONFIG=/Users/phecht/p4config/main.P4CONFIG
Either would give me:
phecht$ p4 set
P4CHARSET=utf8 (config)
P4CLIENT=proda (config)
P4CONFIG=/Users/phecht/p4config/proda.P4CONFIG
P4EDITOR=VI
P4PORT=localhost:1666
Note the "(config)" above shows the value comes from the P4CONFIG file.
