diff --git a/config/.profile.prompt b/config/.profile.prompt index 8506582..1fd90e4 100755 --- a/config/.profile.prompt +++ b/config/.profile.prompt @@ -51,7 +51,6 @@ if [ -n "$PS1" ]; then [ -n "$(which svn)" ] && prompt_check_svn=true [ -n "$(which git)" ] && prompt_check_git=true - [ -n "$(which hg)" ] && prompt_check_hg=true if [ -n "$ZSH_VERSION" ]; then s_host="%m" @@ -68,6 +67,14 @@ if [ -n "$PS1" ]; then # Turn on checkwinsize shopt -s checkwinsize fi + # For hg from FB + if [ -f /usr/share/scm/scm-prompt.sh ]; then + source /usr/share/scm/scm-prompt.sh + prompt_check_hg=true + elif [ -f /opt/facebook/hg/share/scm-prompt ]; then + source /opt/facebook/hg/share/scm-prompt + prompt_check_hg=true + fi # zsh function precmd() { @@ -82,59 +89,68 @@ if [ -n "$PS1" ]; then prompt_extra="" PS1="" if [ "$USER" != "vahagnk" -a "$USER" != "vahagn" ]; then - PS1+="${c_user}${s_user}@" # username@ + PS1+="\[${c_user}\]${s_user}@" # username@ fi - PS1+="${c_host}${s_host}:" # hostname - PS1+="${c_time}${s_time}" # time - PS1+=" ${c_cwd}${s_cwd}" # working_dir + PS1+="\[${c_host}\]${s_host}:" # hostname + PS1+="\[${c_time}\]${s_time}" # time + PS1+=" \[${c_cwd}\]${s_cwd}" # working_dir # # git branch if exist # if [ -n "$prompt_check_git" ]; then local git_branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null | tr -d ' ') if [ -n "$git_branch" ]; then - PS1+="${c_branch}@${git_branch}" - fi + PS1+="\[${c_branch}\]@${git_branch}" + fi + fi + # + # hg branch if exist + # + if [ -n "$prompt_check_hg" -a -z "$git_branch" ]; then + local hg_branch=$(_scm_prompt %s) + if [ -n "$hg_branch" ]; then + PS1+="\[${c_branch}\]@${hg_branch}" + fi fi # # svn branch if exist # if [ -n "$prompt_check_svn" ]; then - local svn_rev=$(svn info . 2> /dev/null | awk -F ':' '/Revision:/ { print $2 }') - if [ -n "$svn_rev" ]; then - PS1+="${c_branch}@${svn_rev}" # svn revision - fi + local svn_rev=$(svn info . 2> /dev/null | awk -F ':' '/Revision:/ { print $2 }') + if [ -n "$svn_rev" ]; then + PS1+="\[${c_branch}\]@${svn_rev}" # svn revision + fi fi # - # Python venv. + # Python venv # local jobs_bg=$(jobs -r | wc -l | tr -d ' ') if [ -n "$VIRTUAL_ENV" ]; then # PS1+=",\[${c_info}\]$(realpath --relative-to=$PWD $VIRTUAL_ENV)" - PS1+=",${c_info}$(basename $VIRTUAL_ENV)" + PS1+=",\[${c_info}\]$(basename $VIRTUAL_ENV)" fi # # Info about jobs. # local jobs_bg=$(jobs -r | wc -l | tr -d ' ') if [ $jobs_bg -gt 0 ]; then - PS1+=",${c_info}bg=${jobs_bg}" + PS1+=",\[${c_info}\]bg=${jobs_bg}" fi local jobs_stopped=$(jobs -s | wc -l | tr -d ' ') if [ $jobs_stopped -gt 0 ]; then - PS1+=",${c_info}stp=${jobs_stopped}" + PS1+=",\[${c_info}\]stp=${jobs_stopped}" fi # # exit code if not zero # if [ "$exit_code" -ne "0" ]; then - PS1+=",${c_error}rc=${exit_code}" + PS1+=",\[${c_error}\]rc=${exit_code}" fi # # Colors should be set here and surrounded with \[\]otherwise bash fails to # calculate prompt length. The text is set through PROMPT_COMMAND - PS1+="${c_reset}\$ " # reset colors and print $ + PS1+="\[${c_reset}\]\$ " # reset colors and print $ } fi