zsh-workers
 help / color / mirror / code / Atom feed
* New test character V for conditional prompts
@ 2008-06-24  0:19 Mikael Magnusson
  0 siblings, 0 replies; only message in thread
From: Mikael Magnusson @ 2008-06-24  0:19 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-06-24  0:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-24  0:19 New test character V for conditional prompts Mikael Magnusson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).