This will run
displayPS1, and the
if statements within once, assigning the result to the prompt. The conditions won't be processed again after that.
Instead, put the function call in
PROMPT_COMMAND, so it gets called every time the prompt is going to be printed. So either
or perhaps rather
setPS1 a function that sets
PS1 itself. (Getting rid of the command substitution saves a fork from the subshell invocation every time the prompt is changed.)