bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

PATCH: Add \? to get PIPESTATUS information in the prompt


From: Wesley J Landaker
Subject: PATCH: Add \? to get PIPESTATUS information in the prompt
Date: Tue, 4 Sep 2001 19:39:03 -0600

Hello Bash-Bug person/people, =)

I use bash all the time, but there is one thing that always bugged me 
that tcsh had that bash didn't: the ability to get the return code from 
the last process (or pipeline) embedded easily in the prompt.

This is possible to do, sure, with PROMPT_COMMAND and so forth, but 
it's rather annoying, because running PROMPT_COMMAND actually modifies 
PIPESTATUS, and so forth.

Anyway, I added this tiny little patch to parse.y that lets you use \? 
(as in $?) in the prompt to get the value of PIPESTATUS:

--- parse.y     Tue Mar 27 08:06:12 2001
+++ parse.wjl.y Tue Sep  4 19:37:56 2001
@@ -3587,4 +3587,5 @@
        \!      the history number of this command
        \$      a $ or a # if you are root
+        \?      the status of the most recent pipeline exit status
        \nnn    character code nnn in octal
        \\      a backslash
@@ -3605,4 +3606,5 @@
   char *temp, octal_string[4];
   time_t the_time;
+  ARRAY *pipestatus;
 
   result = xmalloc (result_size = PROMPT_GROWTH);
@@ -3824,4 +3826,17 @@
              *t = '\0';
              goto add_string;
+
+            case '?':
+             pipestatus = array_cell(find_variable("PIPESTATUS"));
+              if (!pipestatus || array_num_elements(pipestatus) < 1)
+                {
+                  temp = xmalloc(2);
+                  strcpy(temp,"0");
+                }
+              else
+                {
+                 temp = array_to_string(pipestatus," ",0);
+                }
+              goto add_string;
 
            case 'j':


-- 
Wesley J. Landaker - wjl@mindless.com
http://www.landaker.net            PGP DSS/DH Key: 0x0F338E07
PGPKey FP: 3AAA 424B B488 198E B68B  C0E5 390A BACA 0F33 8E07



reply via email to

[Prev in Thread] Current Thread [Next in Thread]