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

Re: PATCH: evaluation depth in prompts



On Aug 26,  6:10pm, Peter Stephenson wrote:
} Subject: PATCH: evaluation depth in prompts
}
} On Tue, 26 Aug 2014 17:40:29 +0100
} Peter Stephenson <p.stephenson@xxxxxxxxxxx> wrote:
} > A better solution might be for a prompt escape that tracks the
} > nesting level (which is trivial apart from picking a new letter).
} 
} %e for evaluation depth (%E is taken but %e isn't).

Nifty, but it should also be added as %N(e.deep.shallow).


diff --git a/Doc/Zsh/prompt.yo b/Doc/Zsh/prompt.yo
index 183a93a..17af5b0 100644
--- a/Doc/Zsh/prompt.yo
+++ b/Doc/Zsh/prompt.yo
@@ -305,6 +305,7 @@ least var(n) elements relative to the root directory, hence tt(/) is
 counted as 0 elements.)
 sitem(tt(D))(True if the month is equal to var(n) (January = 0).)
 sitem(tt(d))(True if the day of the month is equal to var(n).)
+sitem(tt(e))(True if the evaluation depth is at least var(n).)
 sitem(tt(g))(True if the effective gid of the current process is var(n).)
 sitem(tt(j))(True if the number of jobs is at least var(n).)
 sitem(tt(L))(True if the tt(SHLVL) parameter is at least var(n).)
diff --git a/Src/prompt.c b/Src/prompt.c
index 4762535..9ed6c54 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -372,6 +372,17 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 		    if (t0 >= arg)
 			test = 1;
 		    break;
+		case 'e':
+		    {
+			Funcstack fsptr = funcstack;
+			test = arg;
+			while (fsptr && test > 0) {
+			    test--;
+			    fsptr = fsptr->prev;
+			}
+			test = !test;
+		    }
+		    break;
 		case 'L':
 		    if (shlvl >= arg)
 			test = 1;



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