Machine A: MacBook Professional 2017 operating Ventura.
Machine B: MacBook Professional M2 operating Sonoma (Pre-Launch).
My bash PS1 immediate (outline in ~/.bash_profile) is outlined thus:
perform rgb {
# https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
let "sum = 16 + 36*$1 + 6*$2 + $3"
# echo "[e[${sum}m]"
tput setaf ${sum}
}
BOLD=$(tput daring)
DIM=$(tput dim)
RESET=$(tput sgr0)
BRIGHT=$(rgb 5 5 5)
BLUE=$(rgb 1 1 5)
YELLOW=$(rgb 4 4 1)
PS1="n"
PS1+="🧢 [${DIM}]"
PS1+="u"
PS1+="${BRIGHT}@"
PS1+="[${BRIGHT}]"
PS1+="h "
PS1+="[${BLUE}]"
PS1+="w "
PS1+="n"
PS1+="[${BRIGHT}]"
PS1+="> "
PS1+="[${BOLD}]"
Machine A it really works:
Machine B, not fairly:
And I can not determine why.
On a given machine there’s consistency between Terminal.app, iTerm2 and VSCode Built-in Terminal.
So I went again to fundamentals, and found that on each machines, this works appropriately:
> echo -e " 33[32mThis should be green 33[0m"
… while this fails (comes out in white):
> tput setaf 2; echo "This should be green"
I’m surprised to observe this behaviour on machine A, after so many years without noticing any trouble.
So, I’m facing two puzzles:
- why is my prompt failing on machine B
- why is that
tput
failing on both machines?
Should I just be avoiding tput here? I’m guessing I only did it because it looks cleaner than escape sequences.