0

Hi i'm new to command line interface on OSX. before I started to code, I changed bash color I like.

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

#export PS1="\W \$"
export PS1="\[\e[0;36m\W\e[m\e[32m\$(parse_git_branch)\[\033[00m\] $ "

#hightlight path
alias ls="ls -G"

it works fine mostly but when i move to previous command with up and down key, previous command covers current dir like this.

Desktop $
Descd ~

is there any documentation that i can learn more about PS1 setting and solve this problem?

thanks in advance.

gnujoow
  • 374
  • 1
  • 3
  • 16

1 Answers1

0

You only want to enclose characters that don't advance the cursor inside \[...\].

Compare your prompt on top with the correct prompt on the bottom.

export PS1="\[\e[0;36m\W\e[m\e[32m\$(parse_git_branch)\[\033[00m\] $ "
export PS1="\[\e[0;36m\]\W\[\e[32m\]\$(parse_git_branch)\[\033[00m\] $ "

(I took the liberty of removing an apparently unnecessary \e[m from the middle of your prompt as well.)

chepner
  • 497,756
  • 71
  • 530
  • 681
  • thanks a lot @chepner it seems like i missed it when i code it XD. Additionally can you recommend any document for learning bash command ? i want to learn more about it. – gnujoow Aug 26 '16 at 14:32