Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've written a bash script to put git info into my bash prompt, along with still keeping the terminal's pwd in the title bar, to allow for new tabs to be opened at the current working directory. It all works well except that when I make a new tab the it info in the original tab clears until I click enter to refresh it.

Below is my entiere .bash_profile

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

function git_prompt() {
  local status=`git status 2>&1`

  if ! [[ $status =~ "Not a git repository" ]]; then
    # get the current branch
    local branch=`git branch | ack -o '(?<=\* ).*'`

    # set the color according to the status of the git repo
    if [[ $status =~ "nothing to commit" ]]; then
      local color=42
    elif [[ $status =~ "nothing added to commit but untracked files present" ]]; then
      local color=43
    else
      local color=45
    fi

    echo -ne "\033["$color"m"$branch"\033[49m "
  fi
}

function my_prompt() {
  ## PWD IN TITLE FOR NEW TAB LOCATION DETECTION
  update_terminal_cwd

  ## GIT BRANCH AND STATUS DISPLAY
  git_prompt
}


## SETTINGS ############################################################
########################################################################

# custom bash prompt
PS1='\[\e[1;34m\]\W \$\[\e[0m\] '

# scripts that need to be run before display of bash prompt 
PROMPT_COMMAND=my_prompt
share|improve this question

1 Answer 1

This basically happens because while loading ~/.bashrc it doesn't consider to properly include ~/.bash_profile

Just append these lines at the end of your ~/.bashrc, it should do the magic.

if [ -f ~/.bash_profile ]; then
    . ~/.bash_profile
fi

Works for me well :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.