How to Make Commands Bold in Zsh – Custom Prompt Setup

colorspromptzsh

I have set up my bash shell so that any commands I type appear in bold and the commands' output is shown in normal weight:

enter image description here

I did this by adding \e[01m at the end of my PS1 variable to turn on bold, and using trap DEBUG to turn it off:

trap 'printf "\e[0m" "$_"' DEBUG

That way, the \e[0m is printed before each command is executed and I get normal font weight in the output.

How would I go about getting the same effect in zsh?

Best Answer

The old-fashioned way was to use POSTEDIT

 POSTEDIT=$'\e[0m'

(and by the way this isn't bash, don't use a DEBUG trap to simulate preexec: zsh is where it's from) but since zsh 4.3.11 you can use the command line syntax highlighting facility. Let your prompt care only about your prompt and set

zle_highlight=(default:bold)
Related Question