vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| On Thu, 25 May 2006, Marcus Glocker wrote: > > With your diff, the expansion will be done only once, on the initial > > assignment of PS1. I do not see how you'd get the current working dir > > in a prompt with your diff. And what's more, I do not see how the > > current behaviour is non-posix, as you claim. > > Yes, you are right and I am wrong. Sorry about that. I was confused > why it is saying > > PS1="$x$(print \\r)$x$(tput so)$x\$PWD$x$(tput se)$x> " > > and not directly > > PS1='$x$(print \\r)$x$(tput so)$x$PWD$x$(tput se)$x> ' > > but in the end both has the same effect. And after reading that posix > quote again, you are also right, it *shall* be parameter expanded, > which gets lost with my last diff. > > How about this diff. I've updated the regression test a bit which > you can fetch here: > > http://www.nazgul.ch/dev/ksh_regress.tar.gz I have make a diff myself, which also includes the command number stuff. My diff takes a slightly different approach, but has the same effect, AFAIKS. -Otto Index: history.c ================================================== ================= RCS file: /cvs/src/bin/ksh/history.c,v retrieving revision 1.34 diff -u -p -r1.34 history.c --- history.c 17 Mar 2006 16:30:13 -0000 1.34 +++ history.c 24 May 2006 20:28:30 -0000 @@ -851,6 +851,7 @@ histload(Source *s, unsigned char *base, } else { s->line = lno; + s->cmd_offset = lno; histsave(lno, (char *)line, 0); } state = shdr; Index: ksh.1 ================================================== ================= RCS file: /cvs/src/bin/ksh/ksh.1,v retrieving revision 1.112 diff -u -p -r1.112 ksh.1 --- ksh.1 22 Apr 2006 14:10:36 -0000 1.112 +++ ksh.1 24 May 2006 20:28:30 -0000 @@ -1634,7 +1634,6 @@ The current history number (see .Sq \e# , below). -Note: this sequence is not yet implemented. .It Li \e# The current command number. This could be different to the current history number, @@ -1647,7 +1646,6 @@ The default prompt i.e.\& if the effective UID is 0, otherwise .Sq $ \& . -Note: this sequence is not yet implemented. .It Li \e Ns Ar nnn The octal character .Ar nnn . Index: lex.c ================================================== ================= RCS file: /cvs/src/bin/ksh/lex.c,v retrieving revision 1.39 diff -u -p -r1.39 lex.c --- lex.c 10 Apr 2006 14:38:59 -0000 1.39 +++ lex.c 24 May 2006 20:28:30 -0000 @@ -63,6 +63,7 @@ static const char *ungetsc(int); static void gethere(void); static Lex_state *push_state_(State_info *, Lex_state *); static Lex_state *pop_state_(State_info *, Lex_state *); +static char *special_prompt_expand(char *); static int dopprompt(const char *, int, const char **, int); static int backslash_skip; @@ -909,6 +910,7 @@ pushs(int type, Area *areap) s->str = null; s->start = NULL; s->line = 0; + s->cmd_offset = 0; s->errline = 0; s->file = NULL; s->flags = 0; @@ -1120,6 +1122,18 @@ getsc_line(Source *s) set_prompt(PS2, (Source *) 0); } +static char * +special_prompt_expand(char *str) +{ + char *p = str; + + while ((p = strstr(p, "\\$")) != NULL) { + memmove(p, p + 1, strlen(p)); + *p = ksheuid ? '$' : '#'; + } + return str; +} + void set_prompt(int to, Source *s) { @@ -1141,9 +1155,11 @@ set_prompt(int to, Source *s) * unwinding its stack through this code as it * exits. */ - } else - prompt = str_save(substitute(ps1, 0), - saved_atemp); + } else { + /* expand \$ before other substitutions are done */ + char *tmp = special_prompt_expand(ps1); + prompt = str_save(substitute(tmp, 0), saved_atemp); + } quitenv(NULL); break; case PS2: /* command continuation */ @@ -1309,17 +1325,13 @@ dopprompt(const char *sp, int ntruncate, p = str_val(global("PWD")); strlcpy(strbuf, basename(p), sizeof strbuf); break; - case '!': /* '\' '!' history line number XXX busted */ + case '!': /* '\' '!' history line number */ snprintf(strbuf, sizeof strbuf, "%d", source->line + 1); break; - case '#': /* '\' '#' command line number XXX busted */ + case '#': /* '\' '#' command line number */ snprintf(strbuf, sizeof strbuf, "%d", - source->line + 1); - break; - case '$': /* '\' '$' $ or # XXX busted */ - strbuf[0] = ksheuid ? '$' : '#'; - strbuf[1] = '\0'; + source->line - source->cmd_offset + 1); break; case '0': /* '\' '#' '#' ' #' octal numeric handling */ case '1': Index: lex.h ================================================== ================= RCS file: /cvs/src/bin/ksh/lex.h,v retrieving revision 1.10 diff -u -p -r1.10 lex.h --- lex.h 11 Sep 2005 18:02:27 -0000 1.10 +++ lex.h 24 May 2006 20:28:30 -0000 @@ -22,6 +22,7 @@ struct source { char ugbuf[2]; /* buffer for ungetsc() (SREREAD) and * alias (SALIAS) */ int line; /* line number */ + int cmd_offset; /* line number - command number */ int errline; /* line the error occurred on (0 if not set) */ const char *file; /* input file name */ int flags; /* SF_* */ |