From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21424 invoked by alias); 28 Mar 2013 21:15:08 -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: 17741 Received: (qmail 17212 invoked from network); 28 Mar 2013 21:15:07 -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 autolearn=no version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.223.182 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=c3yztKGc3I/ACuHqYEuD/qXgptLs99xVWNpkiuwQndM=; b=gyZJn1gQjMCn6qfKCL9tatKxWRdHp5SStv1lDU/dfP5RcnIT1QCoquSUiaD3slp1Cx BVC1D8heMdmrTsCKWAH9KQDgqB28MLlRdUmPjQ7RL1vwOfPAUkFAaw6mFRR5sDkzrhvg 6VS0qmvX1w6Ry3pRjpNGbvmbL2w05kNn6qPwp45lhdBOUSgttRb80sEuQehnWkO5q2cC 5TJ5423VkMBupNP1OnpAwYzyYzAosDwQHgNrSYDIM9ihOslgvriMt8N0XqpN03oKVrD2 BCKthmhADbn0C0ZA6CH94OBskfg6xzl9GSecRcV0B7Cu/4G3x+G3Kro4F0pkH2xqAjhh yM6w== X-Received: by 10.50.72.3 with SMTP id z3mr8219202igu.47.1364505300450; Thu, 28 Mar 2013 14:15:00 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20130328202651.GA24482@kaeru> References: <20130324192345.GA20437@kaeru> <871ub431wq.fsf@gmail.com> <130325082938.ZM24580@torch.brasslantern.com> <20130325194000.GA27762@kaeru> <20130328202651.GA24482@kaeru> From: TJ Luoma Date: Thu, 28 Mar 2013 17:14:20 -0400 Message-ID: Subject: Re: Outputting colored zsh prompts from an external script To: seanh Cc: zsh-users@zsh.org Content-Type: text/plain; charset=UTF-8 On Thu, Mar 28, 2013 at 4:26 PM, seanh 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.