Index: trunk/src/kash/cd.c
===================================================================
--- trunk/src/kash/cd.c	(revision 1235)
+++ trunk/src/kash/cd.c	(revision 1236)
@@ -335,5 +335,5 @@
  * directory, this routine returns immediately.
  */
-void
+const char *
 getpwd(shinstance *psh, int noerror)
 {
@@ -343,5 +343,5 @@
 
 	if (psh->curdir)
-		return;
+		return psh->curdir;
 
 	if (psh->getpwd_first) {
@@ -353,5 +353,5 @@
 		    stdot.st_ino == stpwd.st_ino) {
 			psh->curdir = savestr(pwd);
-			return;
+			return psh->curdir;
 		}
 	}
@@ -359,5 +359,5 @@
 	find_curdir(psh, noerror);
 
-	return;
+	return psh->curdir;
 }
 
Index: trunk/src/kash/cd.h
===================================================================
--- trunk/src/kash/cd.h	(revision 1235)
+++ trunk/src/kash/cd.h	(revision 1236)
@@ -31,5 +31,5 @@
  */
 
-void	getpwd(struct shinstance *, int);
+const char *getpwd(struct shinstance *, int);
 int	cdcmd(struct shinstance *, int, char **);
 int	pwdcmd(struct shinstance *, int, char **);
Index: trunk/src/kash/parser.c
===================================================================
--- trunk/src/kash/parser.c	(revision 1235)
+++ trunk/src/kash/parser.c	(revision 1236)
@@ -62,4 +62,5 @@
 # include "myhistedit.h"
 #endif
+#include "cd.h"
 #include "shinstance.h"
 
@@ -1621,4 +1622,24 @@
 }
 
+STATIC const char *
+my_basename(const char *argv0, unsigned *lenp)
+{
+	const char *tmp;
+
+    /* skip the path */
+    for (tmp = strpbrk(argv0, "\\/:"); tmp; tmp = strpbrk(argv0, "\\/:"))
+        argv0 = tmp + 1;
+
+	if (lenp) {
+		/* find the end, ignoring extenions */
+		tmp = strrchr(argv0, '.');
+		if (!tmp)
+			tmp = strchr(argv0, '\0');
+		*lenp = (unsigned)(tmp - argv0);
+	}
+	return argv0;
+}
+
+
 STATIC void
 setprompt(shinstance *psh, int which)
@@ -1629,5 +1650,108 @@
 	if (!el)
 #endif
-		out2str(psh, getprompt(psh, NULL));
+	{
+		/* deal with bash prompts */
+		const char *prompt = getprompt(psh, NULL);
+		if (!strchr(prompt, '\\')) {
+			out2str(psh, prompt);
+		} else {
+			while (*prompt) {
+				if (*prompt != '\\') {
+					out2c(psh, *prompt++);
+				} else {
+					prompt++;
+					switch (*prompt++)
+					{
+						/* simple */
+						case '$':	out2c(psh, sh_geteuid(psh) ? '$' : '#'); break;
+						case '\\': 	out2c(psh, '\\'); break;
+						case 'a':	out2c(psh, '\a'); break;
+						case 'e':	out2c(psh, 033); break;
+						case 'n': 	out2c(psh, '\n'); break;
+						case 'r': 	out2c(psh, '\r'); break;
+
+						/* complicated */
+						case 's': {
+							unsigned len;
+							const char *arg0 = my_basename(psh->arg0, &len);
+							outfmt(psh->out2, "%.*s", len, arg0);
+							break;
+						}
+						case 'v':
+							outfmt(psh->out2, "%d.%d", KBUILD_VERSION_MAJOR,
+								   KBUILD_VERSION_MINOR);
+							break;
+						case 'V':
+							outfmt(psh->out2, "%d.%d.%d", KBUILD_VERSION_MAJOR,
+								   KBUILD_VERSION_MINOR, KBUILD_VERSION_PATCH);
+							break;
+							out2str(psh, getpwd(psh, 1) ? getpwd(psh, 1) : "?");
+							break;
+						case 'w':
+						case 'W': {
+							const char *cwd = getpwd(psh, 1);
+							const char *home = bltinlookup(psh, "HOME", 1);
+							size_t home_len = home ? strlen(home) : 0;
+							if (!cwd) cwd = "?";
+							if (!strncmp(cwd, home, home_len)
+							  && (    cwd[home_len] == '\0'
+							      || (cwd[home_len] == '/' && prompt[-1] == 'w'))) {
+								out2c(psh, '~');
+								if (prompt[-1] == 'w' && cwd[home_len]) {
+									out2str(psh, cwd + home_len);
+								}
+							} else if (prompt[-1] == 'w') {
+								out2str(psh, cwd);
+							} else {
+								out2str(psh, my_basename(cwd, NULL));
+							}
+							break;
+						}
+						case '0':
+						case '1':
+						case '2':
+						case '3': {
+							unsigned int ch = prompt[-1] - '0';
+							if (isdigit(*prompt)) {
+								ch *= 8;
+								ch += *prompt++ - '0';
+							}
+							if (isdigit(*prompt)) {
+								ch *= 8;
+								ch += *prompt++ - '0';
+							}
+							out2c(psh, ch);
+							break;
+						}
+
+						/* ignore */
+							break;
+						case '!':
+						case '#':
+						case '@':
+						case 'A':
+						case 'h':
+						case 'H':
+						case 'j':
+						case 'l':
+						case 't':
+						case 'T':
+						case 'u':
+						case '[':
+							if (strchr(prompt, ']')) {
+								prompt = strchr(prompt, ']') + 1;
+							}
+							break;
+						case 'D':
+							if (*prompt == '{' && strchr(prompt, '}')) {
+								prompt = strchr(prompt, '}') + 1;
+							}
+							break;
+					}
+
+				}
+			}
+		}
+	}
 }
 
