Ad

Parse Error Near `]' In Git-prompt.sh When Trying To Update Zshell Prompt

- 1 answer

I'm trying to update my OSX (Monterey 12.1) zshell prompt to include the current Git branch and status. I've copied the latest git-prompt.sh from GitHub (this one) to ~/.git-prompt.sh.

I have the following barebones file at ~/.zshrc per the documentation:

source ~/.git-prompt.sh
setopt PROMPT_SUBST ; PS1='[%[email protected]%m %c$(__git_ps1 " (%s)")]\$ '

When I start a terminal window, I get an error stating there's a "parse error near ']'" on line 318:

Last login: Tue Feb  1 14:06:54 on ttys000
/Users/<user>/.git-prompt.sh:318: parse error near `]'
zsh: command not found: __git_ps1                                                                                       
[<user>@<machine> ~]$ 

Am I somehow doing something incorrectly here? It looks like git-prompt.sh hasn't been changed in a while, so I assume it's stable.

Ad

Answer

As correctly speculated in the comments above, the version of .git-prompt.sh I was using had its tabs replaced with spaces (by my IDE), making parts of the script not get parsed as intended. Copying it from the source into a different text editor that didn't change whitespace resulted in everything working correctly.

Ad
source: stackoverflow.com
Ad