[gnu.bash.bug] Prompt interpretation for bash

james@bigtex.cactus.org (James Van Artsdalen) (06/14/89)

Here's an attempt to get bash to interpret prompt strings like ksh
does.  I don't the code all that well yet, hence the use of alloca to
protect against memory leakage through longjmp().

If all of the magic \ characters available to PS1 were made accessible
shell variables (so shell scripts could use them too), you'd have a
completely general solution.  PROMPT_COMMAND is merely a special case
of this scheme, as in

PS1='`$PROMPT_COMMAND`rest_of_prompt'

***************
*** 472,479 ****
  {
    char *readline_internal ();
    char *value;
  
!   rl_prompt = prompt;
  
    /* If we are at EOF that is what we return. */
    if (rl_pending_input == EOF) {
--- 481,494 ----
  {
    char *readline_internal ();
    char *value;
+   WORD_LIST *wp;
+   WORD_DESC word;
  
!   word.word = prompt;
!   wp = expand_word(&word, 1);
!   rl_prompt = alloca(strlen(wp->word->word));
!   strcpy(rl_prompt, wp->word->word);
!   dispose_words(wp);
  
    /* If we are at EOF that is what we return. */
    if (rl_pending_input == EOF) {

-- 
James R. Van Artsdalen          james@bigtex.cactus.org   "Live Free or Die"
Dell Computer Co    9505 Arboretum Blvd Austin TX 78759         512-338-8789

composer@BU-CS.BU.EDU (06/14/89)

|   Date: 13 Jun 89 18:13:53 GMT
|   From: milano!bigtex!james@cs.utexas.edu  (James Van Artsdalen)
|
|   Here's an attempt to get bash to interpret prompt strings like ksh
|   does.  I don't the code all that well yet, hence the use of alloca to
|   protect against memory leakage through longjmp().
|
|   If all of the magic \ characters available to PS1 were made accessible
|   shell variables (so shell scripts could use them too), you'd have a
|   completely general solution.  PROMPT_COMMAND is merely a special case
|   of this scheme, as in
|
|   PS1='`$PROMPT_COMMAND`rest_of_prompt'

I'm not that familiar with ksh specifics, so I'm not sure what you're
referring to.  But, I'm able to get the same thing to work as what I
believe you want the above to do.

	PS1="`$PROMPT_COMMAND`rest_of_prompt"

The double quotes will allow the $variable to be expanded.  Is this
what you were referring to?

|  James R. Van Artsdalen          james@bigtex.cactus.org   "Live Free or Die"
|  Dell Computer Co    9505 Arboretum Blvd Austin TX 78759         512-338-8789

				-jeff

Jeff Kellem
INTERNET: composer@bu-cs.bu.edu  (or composer%bu-cs.bu.edu@bu-it.bu.edu)
UUCP: ...!harvard!bu-cs!composer

james@bigtex.cactus.org (James Van Artsdalen) (06/14/89)

> From: composer@bu-cs.BU.EDU
> Date:  Tue, 13 Jun 89 18:21:50 EDT

|   Date: 13 Jun 89 18:13:53 GMT
|   From: milano!bigtex!james@cs.utexas.edu  (James Van Artsdalen)

|   PS1='`$PROMPT_COMMAND`rest_of_prompt'

The single quotes are no accident...

> I'm not that familiar with ksh specifics, so I'm not sure what you're
> referring to.  But, I'm able to get the same thing to work as what I
> believe you want the above to do.

> 	PS1="`$PROMPT_COMMAND`rest_of_prompt"

This doesn't do the same thing.

> The double quotes will allow the $variable to be expanded.  Is this
> what you were referring to?

No.  This question is *when* does the string get evaluated.  In your
example it got evaluated immediately and never again.  In my example,
it did not get evaluated immediately, and with my patch, it will be
re-evaluated each time the the prompt is printed.
---
James R. Van Artsdalen          james@bigtex.cactus.org   "Live Free or Die"
Dell Computer Co    9505 Arboretum Blvd Austin TX 78759         512-338-8789