function parse_git_branch_and_add_brackets {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ \[\1\]/'
}
function get_p4set
{
echo `p4 set $1 | sed -e "s/$1=//" -e 's/ (.*)$//' 2>&1`;
return 0;
}
function vcsprompt
{
local NOCOLOR="\[\033[0m\]"
local YELLOW="\e[0;33m"
local GRAY="\[\033[0;37m\]"
local CYAN="\[\033[0;36m\]"
local GREEN="\[\033[0;32m\]"
nP4CLIENT=`get_p4set P4CLIENT`
nP4PORT=`get_p4set P4PORT`
branch=`parse_git_branch_and_add_brackets`
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
if [ -n "$branch" ]
then
PS1="\h:\W \u$GREEN\$branch $NOCOLOR\$ "
elif [ "$nP4CLIENT" = "__client_unset__" ]
then
PS1="\h:\W \u \$ "
else
PS1="\h:\W \u$GRAY[$CYAN\${nP4CLIENT}$GRAY@$YELLOW\${nP4PORT}$GRAY]$NOCOLOR \$ "
fi
}
function pcd {
exist=`p4 -F %depotFile% files "$1"`
path=`p4 -ztag -F %path% where "$1"`
if [ -z "$exist" ]
then
dir=$path
else
dir=`dirname "$path"`
fi
cd "$dir"
}
PROMPT_COMMAND=vcsprompt