25 0q:Basic prompt escapes as shown.
50 if true; then true; else false; fi
57 diff =(print -P '%#') =(print -P '%(!.#.%%)')
58 0:`%#' prompt escape and its equivalent
60 psvar=(caesar adsum jam forte)
66 print -P '%(?.true.false)'
68 print -P '%(?.true.false)'
69 0:ternary prompt escapes
73 print -P 'start %10<...<truncated at 10%<< Not truncated%3< ...<Not shown'
74 print -P 'start %10>...>truncated at 10%>> Not truncated%3> ...>Not shown'
76 >start ...d at 10 Not truncated ...
77 >start truncat... Not truncated ...
79 # It's hard to check the time and date as they are moving targets.
80 # We therefore just check that various forms of the date are consistent.
81 # In fact, if you perform this at midnight it can still fail.
82 # We could test for that, but we can't be bothered.
83 # I hope LC_ALL is enough to make the format what's expected.
89 if [[ $date1 != [A-Z][a-z][a-z][[:blank:]]##[0-9]## ]]; then
90 print "Date \`$date1' is not in the form \`Day DD' (e.g. \`Mon 1'"
92 if [[ $date2 != [0-9][0-9]/[0-9][0-9]/[0-9][0-9] ]]; then
93 print "Date \`$date2' is not in the form \`DD/MM/YYYY'"
95 if [[ $date3 != [0-9][0-9]-[0-9][0-9]-[0-9][0-9] ]]; then
96 print "Date \`$date3' is not in the form \`YY-MM-DD'"
98 if (( $date1[5,-1] != $date2[4,5] )) || (( $date2[4,5] != $date3[7,8] ))
100 print "Days of month do not agree in $date1, $date2, $date3"
102 if (( $date2[1,2] != $date3[4,5] )); then
103 print "Months do not agree in $date2, $date3"
105 if (( $date2[7,8] != $date3[1,2] )); then
106 print "Years do not agree in $date2, $date3"
108 0:Dates produced by prompt escapes
113 (zsh_directory_name() {
116 local -a match mbegin mend
117 if [[ $1 = d ]]; then
118 if [[ $2 = (#b)(*bar)/rod ]]; then
119 reply=(barmy ${#match[1]})
124 if [[ $2 = barmy ]]; then
125 reply=($mydir/foo/bar)
132 print ~[barmy]/anything
137 print ~[scuzzy]/rubbish
140 # catastrophic failure
142 print ~[scuzzy]/rubbish
144 1q:Dynamic named directories
145 >$mydir/foo/bar/anything
149 ?(eval):33: no directory expansion: ~[scuzzy]
152 zsh_directory_name() {
155 local -a match mbegin mend
156 if [[ $1 = n ]]; then
157 if [[ $2 = *:l ]]; then
158 reply=(${2%%:l}/very_long_directory_name)
164 if [[ $2 = (#b)(*)/very_long_directory_name ]]; then
165 reply=(${match[1]}:l ${#2})
173 dir=$parent/very_long_directory_name
178 setopt localoptions xtrace
179 # The following is the key to the test.
180 # It invokes zsh_directory_name which does PS4 output stuff
181 # while we're doing prompt handling for the parameter
182 # substitution. This checks recursion works OK.
184 print ${d//$parent/\<parent\>}
187 # post process error to remove variable contents
189 # tricky: reply is set to include directory length which is variable
190 [[ $line = *reply* ]] && continue
191 print ${line//$parent/\<parent\>}
194 0:Recursive use of prompts
196 ?+zsh_directory_name:1> emulate -L zsh
197 ?+zsh_directory_name:2> setopt extendedglob
198 ?+zsh_directory_name:3> local -a match mbegin mend
199 ?+zsh_directory_name:4> [[ d == n ]]
200 ?+zsh_directory_name:12> [[ <parent>/very_long_directory_name == (#b)(*)/very_long_directory_name ]]
201 ?+zsh_directory_name:14> return 0
202 ?+fn:7> local 'd=~[<parent>:l]'
203 ?+fn:8> print '~[<parent>:l]'