Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Outputting colored zsh prompts from an external script

On Thu, Mar 28, 2013 at 4:26 PM, seanh <snhmnd@xxxxxxxxx> wrote:
> Anyone know how I can make zsh call this script for PROMPT and RPROMPT,
> but fall back on a simple pure-zsh prompt if trying to call the script
> exits with non-zero? (Yes, my zsh-scripting skills really are that
> limited.)
> It does what I wanted from my prompt, with maybe a couple of minor
> wrinkles that could be smoothed out. If I can get custom format options
> working, it might be useful to others who want to design their own
> prompts. I'm thinking it'd work something like this, for example to get
> a zsh prompt with current working dir, virtualenv, git branch and last
> exit status, you would put something like this in your zshrc:
>     PROMPT='$(zshprompt.py --format "{cwd:green} {venv:blue} {git:yellow} {les:red,bold}> ")'
> and zshprompt.py would do all the work to handle current working
> directory truncation and git branch, virtualenv and non-zero exit status
> detection, handle colours and bold etc and transform that (hopefully
> simple) string specification into the much more complex string that zsh
> needs for the prompt.

As someone who has never been able to figure out colors for zsh
prompts, I love this idea.

I don't know if there's a 'better' way to do this, but you could do it this way

FOO="$(a || b)"

if the exit code for 'a' != 0 then b will run.

Messages sorted by: Reverse Date, Date, Thread, Author