zshrc - Using ANSI escape sequences in zsh prompt -


i'm trying use ansi escape sequences set color of zsh prompt, escape character (\e) seems being escaped when displaying prompt. here's example of i'm running , output i'm getting:

> autoload promptinit && promptinit > autoload colors && colors > echo "not sure if 2 lines required" > /dev/null > prompt="\e[32mhi> " \e[32mhi> echo "note escape character wasn't interpreted correctly" > /dev/null \e[32mhi> print -p "$prompt" hi> \e[32mhi> echo "the hi> printed in green, want" > /dev/null 

the zsh print documentation seems -p flag makes print if in prompt, doesn't match actual prompt behavior. know why escape character doesn't work?

i tried using $fg_no_bold, , things $fg_no_bold[red] work, i'd use more 8 standard colors, $fg_no_bold[32] doesn't work (for number, not 32). if getting 256 colors working $fg_no_bold easier, i'd ok doing that!

thanks!

you need use dollar single quote in order tell zsh interpret ansi escape sequences. so

prompt=$'\e[32mhi> ' 

will want, safer additionally put special codes inside %{...%} brackets treat code literally , prevent unwanted moving of cursor position. should change colour default, unless want colourize terminal text foreground green.

after prompt setting should like

prompt=$'%{\e[32m%}hi> %{\e[0m%}' 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -