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

Re: PATCH: _ps1234, _date_formats: Complete strftime formats for %D{}



Mikael Magnusson wrote:
> PS1='%(<tab> no longer tells me "--- number", how is this an
> improvement? It now completes delimiters after PS1='%(3<tab> which I
> would also not consider an improvement :).

I never realised the numbers were also allowed after the (. I've always
had them before.

> There doesn't seem to be a way to get back to completing anything
> after print -P %D\\\{ (pressing tab at this point just deletes two
> backslashes for me, and typing more things does nothing). It's
> probably not a common thing to do though, so if it's complicated then
> don't worry about it on my account.

That wasn't too complicated.

> Let's hope nobody ever tries to use print -rP.

Completing for PS1 is just the same. If you really want to fix this,
check $service, set a variable to (\\|)  and use it with the ~ flag.

Oliver

diff --git a/Completion/Zsh/Type/_ps1234 b/Completion/Zsh/Type/_ps1234
index 8d3c5d8..f182a16 100644
--- a/Completion/Zsh/Type/_ps1234
+++ b/Completion/Zsh/Type/_ps1234
@@ -3,9 +3,7 @@
 local -a specs
 local expl bs suf pre changed=1 ret=1
 
-if [[ -z $compstate[quote] ]]; then
-  bs='\' # in patterns we use (\\|) widely as print -P handles backslashes first
-fi
+[[ -z $compstate[quote] ]] && bs='\'
 
 # first strip off any complete prompt specifications leaving only the
 # current, incomplete, one
@@ -14,10 +12,10 @@ while (( changed )); do
   compset -P '%[DFK](\\|){[^}]#}' && changed=1 # formats with arg: %x{...}
   compset -P '%[0-9-\\]#[^DFK(0-9-<>\\\[]' && changed=1 # normal formats
   compset -P '%[0-9-\\]#(<[^<]#<|>[^>]#>|\[[^\]]#\])' && changed=1 # truncations
-  compset -P '%[0-9-\\]#(\\|)\(??|[^%]' && changed=1 # start of ternary
+  compset -P '%[0-9-\\]#(\\|)\([0-9-]#[^0-9-]?|[^%]' && changed=1 # start of ternary
   compset -P '[^%]##' && changed=1 # sundry other characters
   # %D/%F/%K without a following { ... }
-  [[ $PREFIX = %(-|)<->#[DFK](\\|)[^{\\]* ]] &&
+  [[ $PREFIX = %(-|)<->#[DFK](\\[^{]|[^{\\])* ]] &&
       compset -P '%[0-9\\-]#[DFK]' && changed=1
 done
 [[ $PREFIX = %(-|)<->[FK](#e) ]] && compset -P '*' # F/K with number
@@ -45,12 +43,12 @@ if compset -P '%[FK]'; then
   fi
 fi
 
-if compset -P '%[0-9-\\]#\(?'; then
+if compset -P '%[0-9-\\]#(\\|)\([0-9-]#[^0-9-]'; then
   compset -S '*'
   _delimiters && ret=0
 elif compset -P '%[0-9-\\]#[<>\]]'; then
   _message -e replacements 'replacement string'
-elif compset -P '%[0-9-\\]#(\\|)\('; then
+elif compset -P '%[0-9-\\]#(\\|)\([0-9-]#'; then
   compset -S '[.:+/-%]*' || suf=( -S . )
   compset -S '*'
   specs=(
@@ -76,7 +74,9 @@ elif compset -P '%[0-9-\\]#(\\|)\('; then
     'V:element n of psvar is set and non-empty'
     'w:day of week (Sunday = 0)'
   )
-  _describe -t ternary-prompt-expressions 'ternary prompt format test character' specs $suf && ret=0
+  [[ $IPREFIX != *- ]] && _describe -t ternary-prompt-expressions \
+      'ternary prompt format test character' specs $suf && ret=0
+  _message -e numbers number
 elif compset -P '%D(\\|){'; then
   compset -S '(\\|)}*'
   _date_formats zsh && ret=0
@@ -150,8 +150,7 @@ then
   fi
   _describe -t prompt-format-specifiers 'prompt format specifier' \
       specs -S '' $pre && ret=0
-  (( ! $#pre )) && [[ -prefix '(-|)<->' ]] &&
-      _message -e prompt-format-specifiers number
+  (( ! $#pre )) && _message -e prompt-format-specifiers number
 fi
 
 return ret



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