From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12185 invoked by alias); 5 Aug 2014 07:55:00 -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: 32964 Received: (qmail 26962 invoked from network); 5 Aug 2014 07:54:47 -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.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 From: Bart Schaefer Message-id: <140805005445.ZM27314@torch.brasslantern.com> Date: Tue, 05 Aug 2014 00:54:45 -0700 In-reply-to: <140804135036.ZM1983@torch.brasslantern.com> Comments: In reply to Bart Schaefer "Re: Possible bug to RPROMPT" (Aug 4, 1:50pm) References: <201408041950.s74Jo1PS001579@pws-pc.ntlworld.com> <140804135036.ZM1983@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: Possible bug to RPROMPT MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Aug 4, 1:50pm, Bart Schaefer wrote: } } That'd be interesting, but what's really needed is for %<...< and %>...> } to have a truncation length that's relative to the number of columns } remaining in the line. Hmm, perhaps %12<...< means truncate at 12 } characters, and %-12<...< means to truncate at the remaining length of } the current line minus twelve characters? So, this works (patch below). You can do for example PS1="%-40<<$PS1" and then you always have 40 characters in which to type. It belatedly occurs to me that you can *already* get this with setopt promptsubst PS1='%$((COLUMNS-40))<<'"$PS1" but this seems a worthwhile shorthand and doesn't require promptsubst. On the other hand, if $COLUMNS is less than 40 then the patch below changes the behavior of the promptsubst variant for very narrow windows. It's still tricky to get the leftmost part of the prompt to shrink from the midde, because "remaining width" is always calculated left-to-right. In the patch, I hav enot applied this to the older %[<...] syntax. The second hunks is for something I believe to be a bug, if anyone would care to confirm or deny. diff --git a/Src/prompt.c b/Src/prompt.c index c16d781..c6624cc 100644 --- a/Src/prompt.c +++ b/Src/prompt.c @@ -560,6 +560,12 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep) break; case '<': case '>': + /* Test (minus) here so -0 means "at the right margin" */ + if (minus) { + *bv->bp = '\0'; + countprompt(bv->bufline, &t0, 0, 0); + arg = zterm_columns - t0 + arg; + } if (!prompttrunc(arg, *bv->fm, doprint, endchar, txtchangep)) return *bv->fm; break; @@ -1475,7 +1481,7 @@ prompttrunc(int arg, int truncchar, int doprint, int endchar, /* Now we have to trick it into matching endchar again */ bv->fm--; } else { - if (*bv->fm != ']') + if (*bv->fm != endchar) bv->fm++; while(*bv->fm && *bv->fm != truncchar) { if (*bv->fm == '\\' && bv->fm[1]) -- Barton E. Schaefer