From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17912 invoked by alias); 3 May 2012 19:00:28 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30471 Received: (qmail 8862 invoked from network); 3 May 2012 19:00:17 -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 _spf.google.com designates 209.85.217.171 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:x-mailer; bh=oLSTqkpv54wLnROCOtMd0sjCPxgl7LWQYFZMnfdswbk=; b=rMfqVpIwP8XjrfMqee6rqfTaEkkqhMRNzKOedQ42dmyNEnObtsSp018VKl7xReKGpS 0I/7EhQZICBZJXWOwWDxh3U8HUQwON8k+GMKByoh4hZ0KCQYJ3sxNaoGvRn1Y2GAVR3P UMDh71kwY4tZzD14qmSqxHTqfU8B26W8mO2ZuFmWtDTdzxbHehzm0BtAUH3LUxGVWCfg NxVYcjsFQ+DHj0QqBTeR50AKx9Bhx4QR9BvoqWE4IFy8dtFRdLyT2O6NSx7V+mWiyDg6 TPhmNYALtYnantHzT5/q6cchKlNgjeLGSCc2YDclx/xJATbuX4QE9gaMbhMnU6j4md8m c1pw== From: Mikael Magnusson To: zsh-workers@zsh.org Subject: PATCH (RFC): Parse argument to %F and %K as prompt sequences Date: Thu, 3 May 2012 21:00:02 +0200 Message-Id: <1336071602-31699-1-git-send-email-mikachu@gmail.com> X-Mailer: git-send-email 1.7.10.GIT You can't quote any } inside this argument, but I can't imagine when you'd need to, it's only intended to be used as %F{%3v}. If the code doesn't offend anyone horribly, it should probably be put in a helper function, but I didn't want to bother before I asked if anyone can see any problems with doing this. It does change behaviour as % print -P %F{red1blue} no longer outputs 1blue} in red, but that was a questionable feature I think. print -P %F{red1blue does still work as before though :). --- Src/prompt.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/Src/prompt.c b/Src/prompt.c index e51ce24..c87df54 100644 --- a/Src/prompt.c +++ b/Src/prompt.c @@ -495,10 +495,21 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep) break; case 'F': if (bv->fm[1] == '{') { + char *ep; bv->fm += 2; - arg = match_colour((const char **)&bv->fm, 1, 0); - if (*bv->fm != '}') - bv->fm--; + if ((ep = strchr(bv->fm, '}'))) { + char oc = *ep, *col, *coll; + *ep = '\0'; + coll = col = promptexpand(bv->fm, 0, NULL, NULL, NULL); + *ep = oc; + arg = match_colour((const char **)&coll, 1, 0); + free(col); + bv->fm = ep; + } else { + arg = match_colour((const char **)&bv->fm, 1, 0); + if (*bv->fm != '}') + bv->fm--; + } } else arg = match_colour(NULL, 1, arg); if (arg >= 0 && !(arg & TXTNOFGCOLOUR)) { @@ -516,10 +527,21 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep) break; case 'K': if (bv->fm[1] == '{') { + char *ep; bv->fm += 2; - arg = match_colour((const char **)&bv->fm, 0, 0); - if (*bv->fm != '}') - bv->fm--; + if ((ep = strchr(bv->fm, '}'))) { + char oc = *ep, *col, *coll; + *ep = '\0'; + coll = col = promptexpand(bv->fm, 0, NULL, NULL, NULL); + *ep = oc; + arg = match_colour((const char **)&coll, 1, 0); + free(col); + bv->fm = ep; + } else { + arg = match_colour((const char **)&bv->fm, 1, 0); + if (*bv->fm != '}') + bv->fm--; + } } else arg = match_colour(NULL, 0, arg); if (arg >= 0 && !(arg & TXTNOBGCOLOUR)) { -- 1.7.10.GIT