0

Problem

I have a ps1 script and it's working fine (I'm using \[$(tput setaf x)\]). But when I use a printf with colors I have 2 scenarios:

line overlapping

printf $(tput setaf 2)HI!$(tput sgr0)

Which prints HI! in green but breaks the wrapping

printing \[\]

printf \[$(tput setaf 2)\]HI!\[$(tput sgr0)\]

Which prints \[\]HI!\[\]

Note

I also tried to use echo without success

1 Answers1

0

The solution I found was to change my ps1 from:

RESET="\[$(tput sgr0)\]"
GREEN="\[$(tput setaf 2)\]"

export PS1="${GREEN} MY PS1 ${RESET}"

To:

RESET="$(tput sgr0)"
GREEN="$(tput setaf 2)"

export PS1="\[${GREEN}\] MY PS1 \[${RESET}\]"

As to what happened behind the scenes I still don't know :(