Search code examples
formattingzshps1bold

How do I make the commands I enter bold in ZSH with oh-my-zsh?


I have configured PS1 and made the entire prompt bold

.zshrc contains as follows

PS1="%{$fg_bold[yellow]%}%n@%m %{$fg[blue]%}%~ \$ %{$reset_color%}%{$fg_bold[white]%}"
preexec() { printf "\e[1m"; }

Whatever I type in after the prompt is appearing bold only when I load from the buffer. For example, as shown here me typing echo "this is text" does not appear in bold.

I am on Ubuntu 18.04 and am trying to move to zsh.


Solution

  • The Zshell Line Editor (zle) lets you format the command buffer.

    PS1='%F{yellow}B%n@%m %F{blue}%~ \$ %f%b'  # simplified prompt
    
    zle_highlight=(default:bold,fg=white)
    

    More information about how to use zle_highlight can be found in man zshzle.


    Based on the linked screenshot, it looks like something is already formatting your the command input; you may want to run print $zle_highlight first to see its current value and modify it accordingly, or research your existing configuration for the source of the current colorization.