From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28123 invoked from network); 13 Jul 2000 11:13:06 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 13 Jul 2000 11:13:06 -0000 Received: (qmail 19386 invoked by alias); 13 Jul 2000 11:12:54 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 12242 Received: (qmail 19379 invoked from network); 13 Jul 2000 11:12:53 -0000 Date: Thu, 13 Jul 2000 12:12:26 +0100 From: Peter Stephenson Subject: Re: Zsh 3.1.{6,9} patches In-reply-to: "Your message of Thu, 13 Jul 2000 13:59:44 +0400." To: zsh-workers@sunsite.auc.dk (Zsh hackers list), "Fr. Br. George" Message-id: <0FXM00B0PV4PW3@la-la.cambridgesiliconradio.com> Content-transfer-encoding: 7BIT > The first one is code to meke zsh truncate PS1 string backwards. > Just use zro-started argument with %~ command to drop out the REST of > path instead ofte HEAD. See the example (note %01~ entry): > user@host:/usr..zsh/3.1.9/zsh> pwd; echo $PS1 > /usr/local/lib/zsh/3.1.9/zsh > %U%n%u@%B%m%b:%5(~:%01~..%3~:%~)> This is a good idea, but I'd prefer if it used negative integers instead of integers beginning with zero, as in the following patch. I've used minuses in other places where it seems appropriate. I couldn't try it for trailing hostname components, however, because this is initialised from gethostname(), and although it sets $HOST it continues to use the internal variable hostnam. In fact, the only use of that seems to be for printing a prompt. Would anyone object if I got rid of hostnam and made the prompt code read $HOST? The only user-visible change would be that the prompt reflects changes in $HOST, as it already does with $HOME. > The second one is Solaris 2.7+ configure patch to make it compile zsh > with libcurses.so by default instead of termcap, which is unnative. This is perfectly believable, though I never tried. > - freebsd*|linux*|irix*|osf*) DLLDFLAGS="${DLLDFLAGS=-shared}" ;; > + solaris*|freebsd*|linux*|irix*|osf*) DLLDFLAGS="${DLLDFLAGS=-shared}" ;; ... > - solaris*|sysv4*|esix*) DLLDFLAGS="${DLLDFLAGS=-G}" ;; > + sysv4*|esix*) DLLDFLAGS="${DLLDFLAGS=-G}" ;; Are you sure this is right? ld and cc on this solaris system definitely use -G, not -shared. Index: Doc/Zsh/prompt.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/prompt.yo,v retrieving revision 1.2 diff -u -r1.2 prompt.yo --- Doc/Zsh/prompt.yo 2000/05/22 15:01:35 1.2 +++ Doc/Zsh/prompt.yo 2000/07/13 11:04:40 @@ -44,7 +44,8 @@ item(tt(%/))( Present working directory (tt($PWD)). If an integer follows the `tt(%)', it specifies a number of trailing components of tt($PWD) to show; zero -means the whole path. +means the whole path. A negative integer specifies leading components, +i.e. tt(%-1d) specifies the first component. ) item(tt(%~))( As tt(%d) and tt(%/), but if tt($PWD) has a named directory as its prefix, @@ -64,7 +65,8 @@ item(tt(%m))( The hostname up to the first `tt(.)'. An integer may follow the `tt(%)' to specify -how many components of the hostname are desired. +how many components of the hostname are desired. With a negative integer, +trailing components of the hostname are shown. ) item(tt(%S) LPAR()tt(%s)RPAR())( Start (stop) standout mode. @@ -93,7 +95,7 @@ currently executing, whichever was started most recently. If there is none, this is equivalent to the parameter tt($0). An integer may follow the `tt(%)' to specify a number of trailing path components to show; zero -means the full path. +means the full path. A negative integer specifies leading components. ) item(tt(%i))( The line number currently being executed in the script, sourced file, or @@ -126,7 +128,7 @@ item(tt(%_))( The status of the parser, i.e. the shell constructs (like `tt(if)' and `tt(for)') that have been started on the command line. If given an integer -number that many strings will be printed; zero or no integer means +number that many strings will be printed; zero or negative or no integer means print as many as there are. This is most useful in prompts tt(PS2) for continuation lines and tt(PS4) for debugging with the tt(XTRACE) option; in the latter case it will also work non-interactively. @@ -145,7 +147,8 @@ item(tt(%v))( vindex(psvar, use of) The value of the first element of the tt(psvar) array parameter. Following -the `tt(%)' with an integer gives that element of the array. +the `tt(%)' with an integer gives that element of the array. Negative +integers count from the end of the array. ) item(tt(%{)...tt(%}))( Include a string as a literal escape sequence. @@ -163,10 +166,9 @@ and var(false-text) may both contain arbitrarily-nested escape sequences, including further ternary expressions. -The left -parenthesis may be preceded or followed by a positive integer var(n), -which defaults to zero. The test character var(x) may be any of the -following: +The left parenthesis may be preceded or followed by a positive integer var(n), +which defaults to zero. A negative integer will be multiplied by -1. +The test character var(x) may be any of the following: startsitem() sxitem(tt(c)) Index: Src/prompt.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/prompt.c,v retrieving revision 1.1.1.13 diff -u -r1.1.1.13 prompt.c --- Src/prompt.c 2000/03/24 10:43:21 1.1.1.13 +++ Src/prompt.c 2000/07/13 11:04:41 @@ -113,15 +113,26 @@ if (npath) { char *sptr; - for (sptr = modp + strlen(modp); sptr > modp; sptr--) { - if (*sptr == '/' && !--npath) { - sptr++; - break; + if (npath > 0) { + for (sptr = modp + strlen(modp); sptr > modp; sptr--) { + if (*sptr == '/' && !--npath) { + sptr++; + break; + } } + if (*sptr == '/' && sptr[1] && sptr != modp) + sptr++; + stradd(sptr); + } else { + char cbu; + for (sptr = modp+1; *sptr; sptr++) + if (*sptr == '/' && !++npath) + break; + cbu = *sptr; + *sptr = 0; + stradd(modp); + *sptr = cbu; } - if (*sptr == '/' && sptr[1] && sptr != modp) - sptr++; - stradd(sptr); } else stradd(modp); @@ -199,14 +210,26 @@ for (; *fm && *fm != endchar; fm++) { arg = 0; if (*fm == '%' && isset(PROMPTPERCENT)) { - if (idigit(*++fm)) { - arg = zstrtol(fm, &fm, 10); + int minus = 0; + fm++; + if (*fm == '-') { + minus = 1; + fm++; } + if (idigit(*fm)) { + arg = zstrtol(fm, &fm, 10); + if (minus) + arg *= -1; + } else if (minus) + arg = -1; if (*fm == '(') { int tc, otrunclen; if (idigit(*++fm)) { arg = zstrtol(fm, &fm, 10); + } else if (arg < 0) { + /* negative numbers don't make sense here */ + arg *= -1; } test = 0; ss = pwd; @@ -354,13 +377,20 @@ case 'm': if (!arg) arg++; - for (ss = hostnam; *ss; ss++) - if (*ss == '.' && !--arg) - break; - t0 = *ss; - *ss = '\0'; - stradd(hostnam); - *ss = t0; + if (arg < 0) { + for (ss = hostnam + strlen(hostnam); ss > hostnam; ss--) + if (ss[-1] == '.' && !++arg) + break; + stradd(ss); + } else { + for (ss = hostnam; *ss; ss++) + if (*ss == '.' && !--arg) + break; + t0 = *ss; + *ss = '\0'; + stradd(hostnam); + *ss = t0; + } break; case 'S': txtchangeset(TXTSTANDOUT, TXTNOSTANDOUT); @@ -509,6 +539,8 @@ case 'v': if (!arg) arg = 1; + else if (arg < 0) + arg += arrlen(psvar) + 1; if (arrlen(psvar) >= arg) stradd(psvar[arg - 1]); break; @@ -732,7 +764,7 @@ static int prompttrunc(int arg, int truncchar, int doprint, int endchar) { - if (arg) { + if (arg > 0) { char ch = *fm, *ptr, *truncstr; int truncatleft = ch == '<'; int w = bp - buf; -- Peter Stephenson Cambridge Silicon Radio, Unit 300, Science Park, Milton Road, Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070