Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Outputting colored zsh prompts from an external script
- X-seq: zsh-users 17735
- From: seanh <snhmnd@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Outputting colored zsh prompts from an external script
- Date: Sun, 24 Mar 2013 20:23:45 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:date:from:to:subject:message-id:mime-version :content-type:content-disposition:user-agent; bh=pPbJPzmud8Dp4dtxZBVITtx8qpVtNJVe47El9wZvWyc=; b=b/hXRHXV3dCuWYIldyueWuOPynvzcoxjJD5K9V0WHAA4w1ZH8+0tsFAGQh/IZKicg3 JdNaugtiu63z8H7KfNvVs+x+Ylg3IE+EzsEmkvHOtDbsHmzBfoNNvXRhfK+8xPxsqCzs ylUolbpW0Lq8ZRaAFzCAhbqKKzJtQCIgQxylgl252cLLWmIsACt5fHOJSZR7aLr0D26o AHtVZiR3tUVjnjlbmIvjxbbZMr1zbotkKPcxXdxCCCoi0BN6CSxXbExI855BJiOZ3y/O n6kq7NXv2+YTj1D3Lw7DffUOo/8BJ+HOJ1JitQFdGnjJqmPysRLanQ95hxFr7sqVgpAP bvcA==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
Hey,
I'm trying to write a Python script to handle my zsh prompts. The idea
is to call my Python script from my zshrc to define my PROMPT and
RPROMPT:
PROMPT='$(zshprompt.py left)'
RPROMPT='$(zshprompt.py right --last-exit-status=$?)'
(I also want to make it fall back on a default, pure-zsh prompt if
zshprompt.py returns a non-zero exist status, but that's to do later.)
The Python script then prints whatever it wants to stdout to form the
prompt and right prompt. The full code is here:
https://gist.github.com/seanh/5233082
This all works fine, I've got my Python script ouptutting a nicely
truncated current working directory, name of the active virtualenv if
any, name of the current git branch if in a git repo, exit status of the
last command if non-zero, and user@host if using an ssh connection.
The problem comes when I try to introduce colors into the prompts. As
you can see from the Python code it's printing out ANSI escape sequences
to color the prompts, but this messes up the positioning of the right
prompt and cursor in zsh. Here's a screenshot showing the problem:
https://www.dropbox.com/s/4nqs7ceojmqqtmi/Screenshot%20from%202013-03-24%2020%3A01%3A21.png
The cursor has been pushed right along to left edge of the terminal
(instead of being after the left prompt as it should be), and the right
prompt seems to get pushed further and further to the left as more ANSI
escape codes come into the prompts.
Here's a screenshot of the same thing but with zshprompt.py's color()
function disabled, so you can see where everything's supposed to be:
https://www.dropbox.com/s/dg0p9741ip7zx1m/Screenshot%20from%202013-03-24%2020%3A00%3A35.png
I also tried getting zshprompt.py to print out zsh color codes like
%{$fg[red]%}FOO%{$reset_color%}, but zsh doesn't seem to interpret these
when they're printed by zshprompt.py, it just prints them out into the
prompts literally. I tried various zsh options with this, such as
setopt promptpercent and setopt promptsubst, and tried various other ways of
calling the Python script, such as within double-quotes or back-ticks
instead of single-quotes, or without any quotes at all. Nothing worked.
Any idea how I can do colour prompts from within my Python script?
Thanks
Messages sorted by:
Reverse Date,
Date,
Thread,
Author