Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: prompt memory handling is screwy
- X-seq: zsh-workers 25931
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-workers@xxxxxxxxxx (Zsh hackers list)
- Subject: Re: PATCH: prompt memory handling is screwy
- Date: Fri, 24 Oct 2008 14:46:14 +0100
- In-reply-to: <19776.1224843888@xxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- Organization: CSR
- References: <19776.1224843888@xxxxxxx>
On Fri, 24 Oct 2008 11:24:48 +0100
Peter Stephenson <pws@xxxxxxx> wrote:
> Some idiot added a new feature recently that let the prompt code
> be called recursively. Currently the prompt code isn't written to
> be called recursively, but luckily that's a fairly straightforward
> change, if boring to rename all the variables.
Here's a test. This is actually more hairy even than the fix: since I'm
testing directory handling I need to output directories and remove the
bits of the path that vary. Hence if it fails it may well be the test, not
the shell. This was giving segmentation violations before the patch.
Index: Test/D01prompt.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D01prompt.ztst,v
retrieving revision 1.4
diff -u -r1.4 D01prompt.ztst
--- Test/D01prompt.ztst 26 Sep 2008 09:11:30 -0000 1.4
+++ Test/D01prompt.ztst 24 Oct 2008 13:33:06 -0000
@@ -147,3 +147,57 @@
>~[scuzzy]/rubbish
>~mydir/foo
?(eval):33: no directory expansion: ~[scuzzy]
+
+ (
+ zsh_directory_name() {
+ emulate -L zsh
+ setopt extendedglob
+ local -a match mbegin mend
+ if [[ $1 = n ]]; then
+ if [[ $2 = *:l ]]; then
+ reply=(${2%%:l}/very_long_directory_name)
+ return 0
+ else
+ return 1
+ fi
+ else
+ if [[ $2 = (#b)(*)/very_long_directory_name ]]; then
+ reply=(${match[1]}:l ${#2})
+ return 0
+ else
+ return 1
+ fi
+ fi
+ }
+ parent=$PWD
+ dir=$parent/very_long_directory_name
+ mkdir $dir
+ cd $dir
+ fn() {
+ PS4='+%N:%i> '
+ setopt localoptions xtrace
+ # The following is the key to the test.
+ # It invokes zsh_directory_name which does PS4 output stuff
+ # while we're doing prompt handling for the parameter
+ # substitution. This checks recursion works OK.
+ local d=${(%):-%~}
+ print ${d//$parent/\<parent\>}
+ }
+ fn 2>stderr
+ # post process error to remove variable contents
+ while read line; do
+ # tricky: reply is set to include directory length which is variable
+ [[ $line = *reply* ]] && continue
+ print ${line//$parent/\<parent\>}
+ done <stderr >&2
+ )
+0:Recursive use of prompts
+>~[<parent>:l]
+?+zsh_directory_name:1> emulate -L zsh
+?+zsh_directory_name:2> setopt extendedglob
+?+zsh_directory_name:3> local -a match mbegin mend
+?+zsh_directory_name:4> [[ d == n ]]
+?+zsh_directory_name:12> [[ <parent>/very_long_directory_name == (#b)(*)/very_long_directory_name ]]
+?+zsh_directory_name:14> return 0
+?+fn:7> local 'd=~[<parent>:l]'
+?+fn:8> print '~[<parent>:l]'
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
Messages sorted by:
Reverse Date,
Date,
Thread,
Author