1

I have set up my bash prompt like so:

vcs(){
  if [ $PROMPT_VCS -eq "1" ] && [ $have_vcprompt -eq "1" ]; then
    echo -en "$(vcprompt -f "on ${EMM}%n${EMW}:%b${G}%m${R}%u${NONE}")"
  fi
}

bash_prompt() {
  case $TERM in
    xterm*|rxvt*)
      local TITLEBAR='\[\033]0;${SHORT_HOST} ${NEW_PWD}\007\]'
      ;;
    *)
    local TITLEBAR=""
    ;;
  esac

  local UC=$EMG
  [ $UID -eq 0 ] && UC=$EMR

  local ARROW_COLOR=$EMR
  [ $? -eq 0 ] && ARROW_COLOR=$EMG

  PS1="\[${TITLEBAR}\
${UC}\u \
${NONE}at ${EMY}\h \
${NONE}in ${EMB}\${NEW_PWD} \
${NONE}\$(vcs) \
${K} \
\[${NONE}\]\n\[${ARROW_COLOR}\]\$ \[${NONE}\]"

}

This works perfectly on my laptop running Debian, but on Windows, using git-bash, I get the following error:

bash: command substitution: line 1: syntax error near unexpected token `)'
bash: command substitution: line 1: `vcs)'

The VC info consequently does not appear in the prompt. I don't understand why git-bash has a problem with that closing bracket..

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
lukas
  • 121
  • 7
  • The error message suggests that the first line is `vcs)` rather than `vcs()`. Is that the case? – John Kugelman Mar 11 '20 at 12:30
  • No, this is copied as is. I can use the `vcs` function as well and it works fine, only in the prompt it seems to cause problems. – lukas Mar 11 '20 at 12:32
  • FWIW, I can reproduce the error message by changing `vcs()` to `vcs)`. – jjramsey Mar 11 '20 at 12:40
  • Maybe git-bash doesn't know the function() {} and you just should do function {} – Gerrit Mar 11 '20 at 12:42
  • I really appreciate your help, but I'm positive the function is not the issue here. I can run it without problems and if I, for example, don't escape the `$` before the command substitution, it "works" as in I get the VC info in the prompt, if I start bash in a git repo. Obviously, that's not how it should work (because `$(vcs)` is only evaluated once), but it shows that the function is not the problem, imo. – lukas Mar 11 '20 at 12:59
  • 1
    Is it a line-ending problem? CR-LF instead of LF perhaps? – Gerrit Mar 11 '20 at 13:00
  • 1
    Someone else already described this problem: https://stackoverflow.com/questions/33220492/ps1-bash-command-substitution-not-working-on-windows-10 – Gerrit Mar 11 '20 at 13:02
  • Was about to celebrate this, but unfortunately changing line-endings (from CR-LF to LF) does not have any effect. – lukas Mar 11 '20 at 13:03
  • It does indeed work when I remove the newline. Bummer, but thanks! – lukas Mar 11 '20 at 13:07
  • Maybe the LF's are reverted back to CR-LF when outputting the prompt on git-bash. – Gerrit Mar 11 '20 at 13:18

1 Answers1

0

Thanks to Gerrit's comment, the answer was found here. The functioning version (including newline) looks like this:

  PS1="\[${TITLEBAR}\
${UC}\u \
${NONE}at ${EMY}\h \
${NONE}in ${EMB}\${NEW_PWD} \
${NONE}\$(vcs) \
${K} \
\[${NONE}\]\[${ARROW_COLOR}\]"$'\n$ '"\[${NONE}\]"

If someone could explain what causes this problem that would be even better.

lukas
  • 121
  • 7