Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 2 Jul 2010 22:17:14 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r209653 - head/bin/sh
Message-ID:  <201007022217.o62MHE58023658@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Fri Jul  2 22:17:13 2010
New Revision: 209653
URL: http://svn.freebsd.org/changeset/base/209653

Log:
  sh: Use $PWD instead of getcwd() for the \w and \W prompt expansions.
  
  This ensures that the logical working directory (which may include
  symlinks) is shown and is similar to the default behaviour of the pwd
  builtin.

Modified:
  head/bin/sh/parser.c

Modified: head/bin/sh/parser.c
==============================================================================
--- head/bin/sh/parser.c	Fri Jul  2 21:31:24 2010	(r209652)
+++ head/bin/sh/parser.c	Fri Jul  2 22:17:13 2010	(r209653)
@@ -1734,7 +1734,8 @@ getprompt(void *unused __unused)
 {
 	static char ps[PROMPTLEN];
 	char *fmt;
-	int i, j, trim;
+	const char *pwd;
+	int i, trim;
 	static char internal_error[] = "<internal prompt error>";
 
 	/*
@@ -1785,17 +1786,15 @@ getprompt(void *unused __unused)
 				 */
 			case 'W':
 			case 'w':
-				ps[i] = '\0';
-				getcwd(&ps[i], PROMPTLEN - i);
-				if (*fmt == 'W' && ps[i + 1] != '\0') {
-					/* Final path component only. */
-					trim = 1;
-					for (j = i; ps[j] != '\0'; j++)
-					  if (ps[j] == '/')
-						trim = j + 1;
-					memmove(&ps[i], &ps[trim],
-					    j - trim + 1);
-				}
+				pwd = lookupvar("PWD");
+				if (pwd == NULL)
+					pwd = "?";
+				if (*fmt == 'W' &&
+				    *pwd == '/' && pwd[1] != '\0')
+					strlcpy(&ps[i], strrchr(pwd, '/') + 1,
+					    PROMPTLEN - i);
+				else
+					strlcpy(&ps[i], pwd, PROMPTLEN - i);
 				/* Skip to end of path. */
 				while (ps[i + 1] != '\0')
 					i++;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201007022217.o62MHE58023658>