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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:34:04+00:00 2026-06-12T01:34:04+00:00

if i run this in command line with in git repo git status 2>

  • 0

if i run this in command line with in git repo

git status 2> /dev/null | grep -iw 'modified'

the output i get

#   modified:   .rvmrc

so my assumption is that if i plug this in into if statement i will get true that will execute the line of code

but when i created function as part of the .bash_profile, and here is the code i have:

## Prompt ##
path="$white\w$reset"
folder_name="$white\W$reset"
git_branch="\$(git branch 2>/dev/null | grep -e '\* ' | sed 's/^..\(.*\)/$red(\1)$reset/')"
rvm="$green(\$(~/.rvm/bin/rvm-prompt i v p))$reset"

# Checks if working tree is dirty
function _git_st {
  if [[ $(git status 2> /dev/null | grep -iw 'modified')  ]]; then
    echo "[x]"
  fi
}
git_st="$yellow`_git_st`$reset"

PS1="$rvm $folder_name $git_branch $git_st \$ "

X is not echoed…. i am bit lost, and not sure what i am doing wrong.

this is the out put i get:

(ruby-1.9.2-p290) folder-git (master)  $ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   .rvmrc
#
no changes added to commit (use "git add" and/or "git commit -a")
(ruby-1.9.2-p290) folder-git (master)  $ 
  • 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-12T01:34:06+00:00Added an answer on June 12, 2026 at 1:34 am

    The reason for this is because you are using a variable git_st to set PS1 which will be evaluated at the time of setting PS1. What you can try is to invoke the function _git_st be called instead of using git_st i.e. try something on the lines of:
    PS1="$rvm $folder_name $git_branch \$(_git_st) \$ ".
    Also you might be interested to know that newer versions of git provide functions along with bash completion which provide such utilities. You can take a look at __git_ps1 function if it is available.
    Hope this helps!
    P.S.: Here is SO post which might provide some pointers for using __git_ps1. This is the quick search result from Google.

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

Sidebar

Related Questions

I want to do this: run a command capture the output select a line
How can I run this on linux command line when my username has an
I want to run this as a batch rather than through the command line:
I want to run weka through the command line. I type in this command:
I have a bash script, that I run like this via the command line:
I have this problem when I run SAS 9.2 on the command line on
I have run this command with root: [root@localhost git-shell-commands]# ssh git@192.168.1.12 git@192.168.1.12's password: Last
Is there a way to run this command line within a Java application? java
I run this command : select * from LIST where JCODE = 8 and
How do I run this command with subprocess? I tried: proc = subprocess.Popen( '''ECHO

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.