summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2010-07-02 22:17:13 +0000
committerjilles <jilles@FreeBSD.org>2010-07-02 22:17:13 +0000
commit4ae2ec7aa4df862de8d4d8b6c37efa9815655a4a (patch)
tree008589aee3a3ae7ac42196f6f39b1801d99837a0 /bin
parent4802d158ef9f040cd3ed205c672e9bd66c031e3d (diff)
downloadFreeBSD-src-4ae2ec7aa4df862de8d4d8b6c37efa9815655a4a.zip
FreeBSD-src-4ae2ec7aa4df862de8d4d8b6c37efa9815655a4a.tar.gz
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.
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/parser.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index d11007e..7f7f0d6 100644
--- a/bin/sh/parser.c
+++ b/bin/sh/parser.c
@@ -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++;
OpenPOWER on IntegriCloud