zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@cambridgesiliconradio.com>
To: zsh-workers@sunsite.auc.dk (Zsh hackers list),
	"Fr. Br. George" <george@po.cs.msu.su>
Subject: Re: Zsh 3.1.{6,9} patches
Date: Thu, 13 Jul 2000 12:12:26 +0100	[thread overview]
Message-ID: <0FXM00B0PV4PW3@la-la.cambridgesiliconradio.com> (raw)
In-Reply-To: "Your message of Thu, 13 Jul 2000 13:59:44 +0400." <Pine.BSF.4.21.0007131253420.99431-300000@balrog.po.cs.msu.su>

> 	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 <pws@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


  reply	other threads:[~2000-07-13 11:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-07-13  9:59 Fr. Br. George
2000-07-13 11:12 ` Peter Stephenson [this message]
2000-07-13 14:56   ` Clint Adams
2000-07-13 15:16     ` Peter Stephenson
2000-07-13 15:53   ` Bart Schaefer
2000-07-13 16:32     ` Peter Stephenson
2000-07-14 11:32   ` Fr. Br. George

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0FXM00B0PV4PW3@la-la.cambridgesiliconradio.com \
    --to=pws@cambridgesiliconradio.com \
    --cc=george@po.cs.msu.su \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).