Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6737325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:14:09+00:00 2026-05-26T11:14:09+00:00

# show git branch function parse_git_branch { git branch –no-color 2> /dev/null | sed

  • 0
# show git branch
function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

function proml {
  local        BLUE="\[\033[0;34m\]"
  local         RED="\[\033[0;31m\]"
  local   LIGHT_RED="\[\033[1;31m\]"
  local       GREEN="\[\033[0;32m\]"
  local LIGHT_GREEN="\[\033[1;32m\]"
  local       WHITE="\[\033[1;37m\]"
  local  LIGHT_GRAY="\[\033[0;37m\]"
  case $TERM in
    xterm*)
    TITLEBAR='\[\033]0;\u@\h:\w\007\]'
    ;;
    *)
    TITLEBAR=""
    ;;
  esac

PS1="${TITLEBAR}\
$WHITE\w$GREEN\$(parse_git_branch)$BLUE\
$GREEN\$ "
PS2='> '
PS4='+ '
}
proml

The previous code returns the branch name three times. I just need to see it once…

~/projects/sms(apps2)$ 
(apps2)
(apps2)

How can I correct this to display just the path + branch?

ie .. ~/projects/sms(apps2)$

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:14:09+00:00Added an answer on May 26, 2026 at 11:14 am

    It’s the last line of your script that messes up things. Calling proml directly from ~/.bash_profile or ~/.bashrc sets PS* environment variables only once, so it won’t be updated when you change folders (and you might have (apps2) displayed in every folder you enter later).

    Instead, proml should be set as PROMPT_COMMAND in last line of your script:

    PROMPT_COMMAND=proml
    

    PROMPT_COMMAND holds the name of the function to be executed each time before bash displays prompt. For more info see here.

    Also, speaking of git-aware shell prompts, there’s one nice addition to what you already have. Apart from current branch, you can get indication about any uncommitted changes. See e.g. this blog post for parse_git_dirty() function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't figure out why git show-branch isn't giving me the same full history
We are using Git and our workflow consists of a 'dev' and 'master' branch
I setup my shell prompt to show git branch. So it looks like /Volumes/android/mydroid/packages/apps/Contacts(1.6_r1.4)
Possible Duplicate: Show the original branch for a commit git version 1.7.4.1 I have
I have a local branch tracking the remote/master branch. After running git-pull and git-log
Possible Duplicate: Show just the current branch in Git I am moving my monotone
When using git, is there a way to show commits made to a branch,
I was trying to merge a dev branch into master. git checkout master git
Here is the man page for git show-ref -d . They also have an
I would like that whenever I run git diff or git show it silently

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.