0

Recently, I had to change the color of the prompt when I enter a specific directory and, back to default prompt color when I leave a specific directory.

To change the color of the prompt when enter a specific directory, I used a combination of direnv and .envrc. In .envrc, I changed the color of the prompt with the following code.

export PROMPT='%S%F{magenta}${PWD##$(git rev-parse --show-toplevel)/} PROD%f%s ➤ '

There was no problem with entering a specific directory and changing the color of prompt, but now when I exit this folder (eg cd ../), I realized that the prompt color does not return to its default color.

How can I get the prompt back to default after leaving the specific directory?

thank you

romainl
  • 186,200
  • 21
  • 280
  • 313
John Smith
  • 21
  • 4
  • By setting the variable `PROMPT` again ..... – user1934428 Oct 25 '22 at 07:26
  • If you want to change the prompt dynamically, your PROMPT string must contain code which is evaluated at runtime, i.e. something like `PROMPT='$(prompt_gen)', where `prompt_gen` is a script you have to write, which produces the prompt string based on the current directory. – user1934428 Oct 25 '22 at 07:28

0 Answers0