summaryrefslogtreecommitdiff
path: root/bin/ksh/lex.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2004-11-06 20:33:01 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2004-11-06 20:33:01 +0000
commit786e8e37571967091485ae0115ef50d13c54c9c3 (patch)
tree1b5a7a8347f12b408fdf308d58221c270933f7ae /bin/ksh/lex.c
parentb8a748de4b6beb04b39e8bc0846e140ae7de48ff (diff)
change \w to output ~/subpath type things, except for root of course
naddy ok
Diffstat (limited to 'bin/ksh/lex.c')
-rw-r--r--bin/ksh/lex.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/bin/ksh/lex.c b/bin/ksh/lex.c
index 4fb9ea12cbb..02866bedbd0 100644
--- a/bin/ksh/lex.c
+++ b/bin/ksh/lex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lex.c,v 1.19 2004/11/04 19:20:07 deraadt Exp $ */
+/* $OpenBSD: lex.c,v 1.20 2004/11/06 20:33:00 deraadt Exp $ */
/*
* lexical analysis and source input
@@ -1306,9 +1306,16 @@ dopprompt(sp, ntruncate, spp, doprint)
break;
case 'w': /* '\' 'w' cwd */
p = str_val(global("PWD"));
- if (strcmp(p, str_val(global("HOME"))) == 0) {
+ n = strlen(str_val(global("HOME")));
+ if (strcmp(p, "/") == 0) {
+ strlcpy(strbuf, p, sizeof strbuf);
+ } else if (strcmp(p, str_val(global("HOME"))) == 0) {
strbuf[0] = '~';
strbuf[1] = '\0';
+ } else if (strncmp(p, str_val(global("HOME")), n)
+ == 0 && p[n] == '/') {
+ snprintf(strbuf, sizeof strbuf, "~/%s",
+ str_val(global("PWD")) + n + 1);
} else
strlcpy(strbuf, p, sizeof strbuf);
break;