NAME

p4prompt - Munge tcsh $prompt values to include client name


SYNOPSIS

p4prompt [-c] [-e] [-p] [--] prompt-value

p4prompt [-v]

See EXAMPLES for more useful incantations.


DESCRIPTION

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).


OPTIONS

-c

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 ``%%@''.

-e

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.

-p

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.

-v

Print the version number and exit.

--

Denotes the end of options. Useful when prompt-value begins with ``-''.


EXAMPLES

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


BUGS


SEE ALSO

p4(1), tcsh(1), csh(1)


AUTHOR

Anders Johnson <anders@ieee.org>