From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 529 invoked by alias); 24 Mar 2013 19:23:57 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17735 Received: (qmail 18569 invoked from network); 24 Mar 2013 19:23:55 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,RCVD_IN_DNSWL_LOW, T_DKIM_INVALID,T_TO_NO_BRKTS_FREEMAIL autolearn=no version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.214.50 as permitted sender) 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== X-Received: by 10.204.228.136 with SMTP id je8mr4167339bkb.93.1364153028663; Sun, 24 Mar 2013 12:23:48 -0700 (PDT) Date: Sun, 24 Mar 2013 20:23:45 +0100 From: seanh To: zsh-users@zsh.org Subject: Outputting colored zsh prompts from an external script Message-ID: <20130324192345.GA20437@kaeru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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