On Tue 2011.03.08 at 09:44 -0500, Dan Harnett wrote:
> > The following substitutes '~' for $HOME in the \W prompt case, taken
> > from \w.  This matches bash's behavior for \W.
> 
> This has bugged me too, and I have a very similar patch in my tree.  The
> exception is the middle conditional.
> 
> > +                           } else if (strncmp(p, str_val(global("HOME")), 
> > n)
> > +                               == 0 && p[n] == '/') {
> > +                                   snprintf(strbuf, sizeof strbuf, "~/%s",
> > +                                       str_val(global("PWD")) + n + 1);
> > +                           } else
> 
> This doesn't belong there.  This effective turns \W into \w if the path
> is somewhere in the user's home directory.  Without that conditional, it
> matches bash.

bah, but I liked that :)  however, you are correct...smaller diff below:

cheers,
okan

Index: ksh.1
===================================================================
RCS file: /home/open/anoncvs/cvs/src/bin/ksh/ksh.1,v
retrieving revision 1.138
diff -u -p -r1.138 ksh.1
--- ksh.1       20 Sep 2010 07:41:17 -0000      1.138
+++ ksh.1       8 Mar 2011 08:42:53 -0000
@@ -1622,6 +1622,9 @@ is abbreviated as
 .It Li \eW
 The basename of
 the current working directory.
+.Dv $HOME
+is abbreviated as
+.Sq ~ .
 .It Li \e!
 The current history number.
 An unescaped
Index: lex.c
===================================================================
RCS file: /home/open/anoncvs/cvs/src/bin/ksh/lex.c,v
retrieving revision 1.44
diff -u -p -r1.44 lex.c
--- lex.c       3 Jul 2008 17:52:08 -0000       1.44
+++ lex.c       8 Mar 2011 15:57:33 -0000
@@ -1324,7 +1324,12 @@ dopprompt(const char *sp, int ntruncate,
                                break;
                        case 'W':       /* '\' 'W' basename(cwd) */
                                p = str_val(global("PWD"));
-                               strlcpy(strbuf, basename(p), sizeof strbuf);
+                               n = strlen(str_val(global("HOME")));
+                               if (strcmp(p, str_val(global("HOME"))) == 0) {
+                                       strbuf[0] = '~';
+                                       strbuf[1] = '\0';
+                               } else
+                                       strlcpy(strbuf, basename(p), sizeof 
strbuf);
                                break;
                        case '!':       /* '\' '!' history line number */
                                snprintf(strbuf, sizeof strbuf, "%d",

Reply via email to