#!/bin/bash
function get_p4set
{
echo `p4 set $1 | sed -e "s/$1=//" -e 's/ (.*)$//' 2>&1`;
return 0;
}
function p4prompt
{
local NOCOLOR="\[\033[0m\]"
local YELLOW="\e[0;33m"
local GRAY="\[\033[0;37m\]"
local CYAN="\[\033[0;36m\]"
nP4CLIENT=`get_p4set P4CLIENT`
nP4PORT=`get_p4set P4PORT`
if [ ${#nP4CLIENT} -eq 0 ]
then
nP4CLIENT="__client_unset__"
fi
if [ ${#nP4PORT} -eq 0 ]
then
# "p4" actually defaults to using "perforce:1666", so the
# P4PORT is never really "unset".
nP4PORT="__server_unset__"
fi
PS1="$GRAY[$CYAN\${nP4CLIENT}$GRAY@$YELLOW\${nP4PORT}$GRAY] \
\${PWD} $NOCOLOR-> "
}
PROMPT_COMMAND=p4prompt