3

I've customized the prompt in my Mac terminal like this:

export PS1="\[\e[31;1m\] \w $ \[\e[0m\] "

This way I get the /working/directory $ in bold red, but I also want to get the command I execute in bold red. Nonetheless, I want the output of the command to be of default color.

Basically I want this:

enter image description here

Any help, please?


EDIT: I tried the code on this answer but at least for me it is not working. It makes the command bold, but also the command output. And in fact I'm getting an extra ${OFF} tag printed after the command output and even a crazy behaviour when I press up key to see previous executed commands...

1
  • Alright, I'm reopening the question and cleaning this comment thread up. Please add a reference to the question I linked to the question and state that it doesn't work (and explain in detail what does happen when you try it). Thanks! – Daniel Beck Mar 8 '14 at 23:08
1

Here's how to do it:

export PS1="\[\e[31;1m\] \w $ "   
trap 'echo -ne "\e[0m" ' DEBUG

All the magic comes from Escapes between command input and output .

2
  • If anyone has compatibility issues with this, try trap "printf '\033[0m'" DEBUG instead. – wjandrea Oct 26 '17 at 19:54
  • On MacOS High Sierra, the printf method works, where the echo method does not. Additionally, it doesn't matter if I use \e or \033 - they both apparently evaluate to the escape character. I also tried swapping the single and double quotes, which also made no difference. – Nate Oct 18 '19 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.