title: Dynamic elements in bash PS1
body: <p>I have put the following in my ~/.localsh file to customize my bash prompt when working with git.</p>
  
  <p>Basically I want to get the current branch displayed in my terminal.
  The gitk tool shows branches with green background and black foreground, so thats what I'm trying to do.</p>
  
  <p>What I have works, but when I press the up arrow on the keyboard to scroll back through previous commands it gets overwritten.</p>
  
  <p>This stuff has happened to be before when you I din't end a color sequence with [\e[0m].
  Now it is happening to me because of calling getgitbranch function.  I think it has something to do with the terminal not knowing how long the prompt is.</p>
  
  <p>So, heres the question...
  How do I correctly use dynamic elements in my bash prompt and not get it hosed up when I use the up arrows?</p>
  
  <pre><code>function getgitbranch()
  {
  git branch | grep "^\*" | cut -c3-
  }
  
  function blabla()
  {
  PS1=""
  PS1="$PS1\[\e[0;30m\]\[\e[42m\]\[\$(getgitbranch)\]\[\e[0;49m\]\[\e[0m\] "
  PS1="$PS1\[\e[1;35m\][\[\e[0m\]"
  PS1="$PS1\[\e[1;33m\]\w\[\e[0m\]"
  PS1="$PS1\[\e[1;35m\]]\[\e[0m\]"
  PS1="$PS1 \[\e[1;31m\]&gt;\[\e[0m\] "
  export PS1
  }
  </code></pre>