From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7470 invoked by alias); 28 Mar 2013 20:27:15 -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: 17740 Received: (qmail 7950 invoked from network); 28 Mar 2013 20:27:03 -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.46 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:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=Mb7cG4W60RGpZ/9Wyem9kO5oYuRGUZzoOqHwpI+OW4s=; b=BbU1vepLkOxsMG+NLIcMXtRVqiH5gSjKWtiuAP7ddwiwXmTbgwWjLdRN6NH12DTV/m X1N0mcszdIAP1Nx34rhVEkFAxe7zDCLkoC9pSchvnjR4BOgAzSkwMwPmLxPUH9dXPon8 QhPV22RJR5EmanP8zxMQgyAlJWmdYYSntXVAzpbFzUdBdU2Fkrml1ZGb4Hc4/TLZkU4Q jjJoAJ4IK/L6H8qxePooexjbEGEd/4gh60p54OJYTwLPYDya2+RaO1dWrMnD9OcuVnzW Zp1thPA0dWcSANzSoiNKacL6+pYlYGUJy6BLB2auo8vRAZI4AgamimX80n+grgX4fSUA ZlDQ== X-Received: by 10.204.165.15 with SMTP id g15mr12707996bky.140.1364502414182; Thu, 28 Mar 2013 13:26:54 -0700 (PDT) Date: Thu, 28 Mar 2013 21:26:51 +0100 From: seanh To: zsh-users@zsh.org Subject: Re: Outputting colored zsh prompts from an external script Message-ID: <20130328202651.GA24482@kaeru> References: <20130324192345.GA20437@kaeru> <871ub431wq.fsf@gmail.com> <130325082938.ZM24580@torch.brasslantern.com> <20130325194000.GA27762@kaeru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130325194000.GA27762@kaeru> User-Agent: Mutt/1.5.21 (2010-09-15) > > > 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.