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 7504121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:27:59+00:00 2026-05-29T21:27:59+00:00

In bash, I’m using a gitprompt to show the current status of my git

  • 0

In bash, I’m using a gitprompt to show the current status of my git repository, so my PS0 looks like this: [time][repo name][current path][number of added/modified files]$
This is set in ~/.bashrc where I’m exporting the PROMPT_COMMAND

export PROMPT_COMMAND=$PROMPT_COMMAND';export PS1=$(gitprompt.pl c=\+ u=\~ f=\* A=\^ B=\\\\ F=\ \>\> statuscount=1)'

I’m also using screen (which may come into play in this question). When I create a new screen window it automatically sources the .bashrc so my PS0 updates with the latest git status for that repo, unfortunately, that is the only time my PS0 updates with the git status.

How would I set this up so my git status updates every time I run a command in terminal or only on certain commands?

I would only need to run a git status when closing a file, moving, deleting or copying; so if I could set the prompt to run only on those commands, that would be best, but I would settle for it running on every bash command (without binding it to my return key).

Here is my entire prompt in ~/.bashrc

export PS0='\[\e[0;32m\][\t]\[\e[1m\][\h]\[\e[0;1m\][\w]\[\e[30;1m\]%{\[\e[1;32m\][%b]\[\e[0m\][%c%u%f%t]%}%{[%B%A%F]%}\[\e[0m\]\u\$ '
PS1=$(gitprompt.pl c=\+ u=\~ f=\* A=\^ B=\\\\ F=\ \>\> statuscount=1)
export PROMPT_COMMAND=$PROMPT_COMMAND';export $PS1'
  • 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-29T21:28:03+00:00Added an answer on May 29, 2026 at 9:28 pm

    It looks to me like the problem you’re encountering is that you’re already inside the single quotes, so it doesn’t want to parse the command a second time. It should be possible to get around that by putting the the PS1 assignment inside a bash function and then setting PROMPT_COMMAND:

    function prompt_command() {
        PS1='$(gitprompt.pl c=\+ u=\~ f=\* A=\^ B=\\\\ F=\ \>\> statuscount=1)'
    }
    
    export PROMPT_COMMAND=prompt_command
    

    It may also be possible to put your gitprompt.pl script inside a function and return the results you need, so that it’s only printing a result if it’s inside a git repository.
    This could be achieved with something similar to the following:

    export PS1='\[\e[1;37m\][\[\e[1;32m\]\h\[\e[1;37m\]:\[\e[1;36m\]\w\[\e[1;37m\]]$(parse_git_branch)$ \[\e[0m\]'
    
    parse_git_branch() {
        BRANCH=$( git branch --no-color 2> /dev/null )
        # only run the gitprompt script if we're in a git repository
        if [ -n "$BRANCH" ]; then
            GITPROMPT=$(gitprompt.pl c=\+ u=\~ f=\* A=\^ B=\\\\ F=\ \>\> statuscount=1)
            printf "\e[1;33m[$GITPROMPT]\e[1;37m"
        fi
    }
    

    (Note: This is untested, it may require a few tweaks)

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

Sidebar

Related Questions

In BASH, I want to do something like this: #!/bin/bash HOST=blah USER=foo REMOTE_ROOT=${HOST}:~${USER}/ REP_NAME=`basename
Note: Bash 3.00 How to substitute this example string 123456789 , to look like
In Bash, we can combine two shell commands cd and ls like this: function
In Bash I'm executing a command and putting the result in a variable like
In bash one can escape arguments that contain whitespace. foo a string This also
In Bash I can easily do something like command1 && command2 || command3 which
Linux bash script: function Print() { echo $1 } Print OK This script runs
In bash I would like to get filename from a command line string. But
this bash script can catch all the environment variables which are set when data
Simple Bash +1 please Hey there. I know I'm missing something simple in this

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.