git-aware-prompt
git-aware-prompt copied to clipboard
Use printf instead of echo in colors.sh
echo (both the built-in command and /bin/echo) doesn't recognize the "\e" escape sequence on OS X. (This may not be an issue, since $TERM is typically only unset in non-interactive environments, so these could theoretically also be replaced with an empty echo or printf.)
This fixed my prompt on OS X. Before it was printing "(master)\e[0m$" from the txtrst escape sequence.
Was master printing in color?
Yes: https://imgur.com/a/99n9jkG (using echo)
Here it is with this patch: https://imgur.com/a/PEhL91H
Weird, I'm guessing your tput doesn't recognize sgr 0 somehow. What version of OS X are you using?
Changing sgr 0 to sgr0 might also work.
Darwin Kernel Version 17.7.0
Like I said, switching to printf fixes the issue.
Right, but the only reason echo or printf are called is because tput fails. So in this case, it's because "tput sgr 0" fails. That's weird, though, because I'm using Darwin 17.6.0 (aka macOS 10.13.5) and it appears to work fine for me. Maybe it has something to do with your terminal, then.
At any rate, this patch would be good to merge for portability reasons in cases like yours.
Ah you're right. I wasn't thinking about the logic. Are you sure that your tput sgr 0 2 isn't exiting 1? You might be hitting the echo/printf as I did.
davidsnyder@loki tictactoe-react (master)*$ tput sgr 0 2
davidsnyder@loki tictactoe-react (master)*$ echo $?
1
tput sgr0 seems to be the correct command? I read that sgr 0 0 is equivalent to sgr0 but sgr 0 0 exits 1 for some reason.
txtrst="$(tput sgr0 2>/dev/null || printf '\e[0m')" # Text Reset works for me.