zsh-users
 help / color / mirror / code / Atom feed
From: seanh <snhmnd@gmail.com>
To: zsh-users@zsh.org
Subject: Re: Outputting colored zsh prompts from an external script
Date: Thu, 28 Mar 2013 21:26:51 +0100	[thread overview]
Message-ID: <20130328202651.GA24482@kaeru> (raw)
In-Reply-To: <20130325194000.GA27762@kaeru>

> > > So far this color issue is the only thing getting in my way...
> > 
> > Your python script needs to either output %F{color} / %K{color} instead
> > of the raw ANSI sequences, or (might be easier) put %{ and %} around the
> > ANSI.  Both methods tell zsh that this output is "zero-width" on the
> > terminal, so it doesn't count those bytes when determing how much screen
> > space the prompt uses.  See also %G in the manual.
> 
> That was exactly what I needed, thanks! Took all of two seconds to apply
> and worked perfectly. I've updated the gist. The Python code could be
> written more clearly, to make it explicit that the ANSI codes are
> getting wrapped in zsh zero-width codes. Once I've given it some testing
> and finished it off, I'll publish the script properly somewhere.

Here's the "finished" version as I'm using it for now:

https://gist.github.com/seanh/5233082

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.


  reply	other threads:[~2013-03-28 20:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-24 19:23 seanh
2013-03-24 21:48 ` Christian Neukirchen
2013-03-25 13:05   ` seanh
2013-03-25 15:29     ` Bart Schaefer
2013-03-25 19:40       ` seanh
2013-03-28 20:26         ` seanh [this message]
2013-03-28 21:14           ` TJ Luoma
2013-03-29 15:07           ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130328202651.GA24482@kaeru \
    --to=snhmnd@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).