Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

New test character V for conditional prompts



Hi,

I'm already using psvar for Some Stuff, and now I wanted to also use it for Some Other Stuff, in both cases my construct looks like %(3v.(%3v).) ie I don't want the parentheses when the psvar is unset. When using psvar for two different things, at least one will currently always enable the other since %(3v..) tests psvar for having at least 3 elements. The following patch adds the V character for testing if element of psvar is actually set to a string (it currently tests false if the element is set but the empty string).

diff --git a/Doc/Zsh/prompt.yo b/Doc/Zsh/prompt.yo
index d517734..3c96733 100644
--- a/Doc/Zsh/prompt.yo
+++ b/Doc/Zsh/prompt.yo
@@ -274,6 +274,7 @@ sitem(tt(S))(True if the tt(SECONDS) parameter is at least var(n).)
 sitem(tt(T))(True if the time in hours is equal to var(n).)
 sitem(tt(t))(True if the time in minutes is equal to var(n).)
 sitem(tt(v))(True if the array tt(psvar) has at least var(n) elements.)
+sitem(tt(V))(True if element var(n) of the array tt(psvar) is set and non-empty.)
 sitem(tt(w))(True if the day of the week is equal to var(n) (Sunday = 0).)
 endsitem()
 )
diff --git a/Src/prompt.c b/Src/prompt.c
index 034a4fa..72ba2e2 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -321,6 +321,12 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 		    if (arrlen(psvar) >= arg)
 			test = 1;
 		    break;
+		case 'V':
+		    if (arrlen(psvar) >= arg) {
+			if (*psvar[(arg ? arg : 1) - 1])
+			    test = 1;
+		    }
+		    break;
 		case '_':
 		    test = (cmdsp >= arg);
 		    break;

--
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author