Reputation: 67177
So, I'm on Windows and play around with my PS1
for the Git bash.
My PS1
looks like this:
PS1="\n\[\033[01;35m\]\u@\h\[\033[01;34m\] $PWD \[\033[00m\]\[\033[01;32m\]$(__git_ps1 "(%s)")\[\033[00m\]\nλ "
Then I noticed that the branch name isn't updated when changing branches, and found this answer, which tells me to exchange the double quotes for single quotes.
Now, my PS1
looks like this:
PS1='\n\[\033[01;35m\]\u@\h\[\033[01;34m\] $PWD \[\033[00m\]\[\033[01;32m\]$(__git_ps1 "(%s)")\[\033[00m\]\nλ '
Suddenly, I recieve warnings when executing my .bashrc
:
bash: command substitution: line 1: syntax error near unexpected token `)'
bash: command substitution: line 1: `__git_ps1 "(%s)")'
Further investigation shows me that when I remove the \n
before the λ
at the end of the PS1
definition, the warning disappears.
Can anyone answer me:
\n
at the end seems totally unrelated to the execution of __git_ps1
to me)?When I change the $(__git_ps1 "(%s)")
to `__git_ps1 "(%s)"`
, the warning is gone and everything works as expected...
Upvotes: 0
Views: 351
Reputation: 673
Solution
NEWLINE="
"
PS1='\[\033[01;35m\]\u@\h \[\033[01;34m\]$PWD\[\033[01;32m\]$(__git_ps1)\[\033[00m\]$NEWLINEλ '
There is trouble involved in the newline being around, also resetting the color was making the line longer than necessary.
Smallest sample of problem:
PS1='$(date)\n$'
Looks like an issue with variable substitution.
Upvotes: 2