p4prompt - Munge tcsh $prompt values to include client name
p4prompt [-c] [-e] [-p] [--] prompt-value
p4prompt [-v]
See EXAMPLES for more useful incantations.
Replaces substrings of the form %@[0[n]] in prompt-value with a string representing the current directory. The replacement is
similar to that of ``%c'' (and its variants) in the tcsh(1) $prompt variable, except that if the current directory appears to be in a Perforce
client workspace, then the root of the client workspace is represented by
``@client''.
Client substitution has precedence over tilde substitution. If $PWD does not appear to belong to a client, then the ``%@'' is simply replaced
with a ``%c'' for tcsh(1) to expand (unless -c is specified; see below).
Unless -p is specified, the client is determined by searching for a file with the
name specified by the value of the $P4CONFIG environment variable, first in $PWD, and then in the directories obtained by stripping off its trailing path
components successively. If such a file is found, then it is assumed to
reside within the client root directory, and the client name is determined
from the line beginning ``P4CLIENT='' in the file.
p4prompt is allegedly intelligent about replacing ``%@'' around other formatting sequences. For example, ``%%@'' and ``%{%@%}'' pass through unmunged (unless -c is specified).
Run in csh(1)-friendly mode. ``%@'' is always expanded, even
if we don't appear to be in a client workspace, because ``%c'' is
meaningless in plain csh(1). The current user's home directory
is replaced with ``~'' whenever it prefixes $PWD. Furthermore, the ``%%''
string is resolved to a single ``%'', so that you can put a literal ``%@''
in the prompt string using ``%%@''.
Missing directory components are replaced with ``...'' rather than ``<n>``. This emulates the behavior when $ellipsis is set in tcsh(1), since
p4prompt can't access $ellipsis directly.
If p4prompt is compiled with the Perforce API linked-in, then this option causes the current client and client root to be determined through p4 info. This is more trustworthy, but it might block if the connection to the server is mal-functional, and therefore it is not recommended by default. The output of p4prompt -v will include the string ``-p enabled'' if and only if p4prompt was compiled with this option available.
Print the version number and exit.
Denotes the end of options. Useful when prompt-value begins with ``-''.
This is what I recommend for a general .cshrc file:
if ( $?tcsh ) then
alias cwdcmd \
'set prompt="`p4prompt '\''%@02 %h%# '\''`"'
cwdcmd
else
alias cwdcmd \
'set prompt="`p4prompt -c '\''%@02 \\\!% '\''`"'
alias cd 'cd \!:*; cwdcmd'
alias pushd 'pushd \!:*; cwdcmd'
alias popd 'popd \!:*; cwdcmd'
cwdcmd
endif
It's actually safer if you specify an absolute path to p4prompt (wherever it's installed on your system), and check that it's available before relying on it, like this:
if ( -x /usr/local/bin/p4prompt ) then
alias cwdcmd \
'set prompt="`/usr/local/bin/p4prompt '\''%@02 %h%# '\''`"'
cwdcmd
else
set prompt='%c02 %h%# '
endif
p4prompt assumes that every client has a $P4CONFIG file at the client root which sets P4CLIENT, and that no other $P4CONFIG
files exist within clients, which is a good discipline to follow anyway.
Use the -p option if these assumptions are known to be invalid.
p4prompt trusts $PWD and $HOME.
As with ``%c'' and friends in tcsh(1), symbolic links in $PWD are treated as real directories. In particular, if you cd'ed to the current client workspace via a symbolic link from outside the
client, then your prompt will not indicate the current client.
p4prompt is written in C because performance is important. That makes it somewhat difficult to maintain.
p4prompt is not portable to non-UNIX systems, mostly due to assumptions regarding
the format of file path names. This is believed not to be important,
because tcsh(1) and csh(1) are not in widespread
use under other systems anyway.
p4prompt is aggressive about recovering from errors, since failing generally causes the prompt to go away, which is unfriendly.
p4(1), tcsh(1), csh(1)
Anders Johnson <anders@ieee.org>