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

  • SEARCH
  • Home
  • 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 8113373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:48:23+00:00 2026-06-06T02:48:23+00:00

For a while now I’ve been using the __git_ps1 function in my bash’s PS1

  • 0

For a while now I’ve been using the __git_ps1 function in my bash’s PS1 prompt
(with PS1='\w$(__git_ps1)'). Now I want to color it depending on branch
status.

I wrote a bash function that checks if the current branch is modified, and
colors red or white depending on the status. The problem is that it uses git
status
to check the status (it’s the only way I know off), and that’s several
times slower than __git_ps1, which is enough to cause an annoying delay when
I’m using the prompt (I’m on a very weak netbook).

So I ask: is there a faster way to check status of the current git folder?
__git_ps1 is a lot faster than manually parsing git branch, so I’m thinking
there might be some other hidden git function.

  • 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-06-06T02:48:25+00:00Added an answer on June 6, 2026 at 2:48 am

    Not entirely your answer, but bash-completion has this built-in.

    If you set the bash ENV GIT_PS1_SHOWDIRTYSTATE to a nonempty value, unstaged (*) and staged (+) changes will be shown next to the branch name. You can configure this per-repository ith the bash.showDirtyState variable, which defaults to true once GIT_PS1_SHOWDIRTYSTATE is enabled.

    You can also see if currently something is stashed, by setting GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed, then a ‘$’ will be shown next to the branch name.

    If you would like to see if there are untracked files, then you can set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there are untracked files, then a ‘%’ will be shown next to the branch name.

    Not sure about the speed degrade when you enable this though.
    If you want to do the coloring:

    Staged files:

    if git rev-parse --quiet --verify HEAD >/dev/null; then
     git diff-index --cached --quiet HEAD -- || color for staged changes
    else
      color unstaged changes
    fi
    

    Stashed files

    git rev-parse --verify refs/stash >/dev/null 2>&1 && color for stashed files
    

    Untracked files

    if [ -n "$(git ls-files --others --exclude-standard)" ]; then
      Color untrack files
    fi
    

    The above snippets come from the bash-completion script.

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

Sidebar

Related Questions

I've been using ajax for a while now and I want to learn more
I've been using TortoiseSVN for a while now for a few of my side
For while now I have been using ezpublish as a framework, and CMS when
For a while now, I'm been using jQuery to offer enhancements via JavaScript on
I've been using NHibernate for a while now, I'm still wondering what the differences
For a while now I've been using subversion for my personal projects. More and
I've been using C# for a while now but haven't really homed in my
For a while now, I've been using web services regardless of the purpose with
I've been using Git for a while now and love the features and flexibility
I've been using OData for a while now and am finding it a fantastic

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.