From 62859f0d7e62ac44cfe3f7d4fb66a3434f140ddb Mon Sep 17 00:00:00 2001
From: Piotr Grzybowski <narsil.pl@gmail.com>
Date: Fri, 14 Nov 2014 17:39:29 +0100
Subject: [PATCH] Shell options in prompt
To: bash

---
 parse.y | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/parse.y b/parse.y
index 815db98..3f551c0 100644
--- a/parse.y
+++ b/parse.y
@@ -5219,6 +5219,7 @@ print_prompt ()
 	\j	the number of active jobs
 	\l	the basename of the shell's tty device name
 	\n	CRLF
+	\o	shell options
 	\r	CR
 	\s	the name of the shell
 	\t	the time in 24-hour hh:mm:ss format
@@ -5256,6 +5257,11 @@ decode_prompt_string (string)
   time_t the_time;
   char timebuf[128];
   char *timefmt;
+  char mode;
+  int value;
+  int index;
+  int count;
+  int temp_size;
 
   result = (char *)xmalloc (result_size = PROMPT_GROWTH);
   result[result_index = 0] = 0;
@@ -5396,6 +5402,44 @@ decode_prompt_string (string)
 	      temp[1] = no_line_editing ? '\0' : '\n';
 	      temp[2] = '\0';
 	      goto add_string;
+	    case 'o':
+	      index = 0;
+	      count = 0;
+	      temp_size = 0;
+	      while (shell_flags[index].value != NULL)
+	        {
+	          if (*(shell_flags[index].value))
+	            {
+	              count++;
+	            }
+	          index++;
+	        }
+	      if (count > 0)
+	        {
+	          temp_size = count + 1;
+	          temp = (char *)xmalloc (temp_size);
+	          if (temp == NULL)
+	            {
+	               goto not_escape;
+	            }
+	          index = 0;
+	          count = 0;
+	          while (shell_flags[index].value != NULL)
+	            {
+	              if (*(shell_flags[index].value) && count < temp_size)
+	                {
+	                  temp[count] = shell_flags[index].name;
+	                  count++;
+	                }
+	              index++;
+	            }
+	          temp[temp_size - 1] = '\0';
+	          goto add_string;
+	        } else {
+	          temp = (char *)xmalloc (1);
+	          temp[0] = '\0';
+	          goto add_string;
+	        }
 
 	    case 's':
 	      temp = base_pathname (shell_name);
-- 
1.8.4

