* PATCH: _ps1234, _date_formats: Complete strftime formats for %D{} @ 2015-07-06 0:36 Mikael Magnusson 2015-07-06 11:11 ` Oliver Kiddle 0 siblings, 1 reply; 12+ messages in thread From: Mikael Magnusson @ 2015-07-06 0:36 UTC (permalink / raw) To: zsh-workers Feel free to hook _date_formats into _date and/or make a _strftime. PS, my strftime(3) says it handles %E and %O, and it does work with date +%Ey, but zsh just prints the literal %Ey. Is it handled wrong by us or not by the libc like the manpage claims? --- Completion/Unix/Type/_date_formats | 80 ++++++++++++++++++++++++++++++++++++++ Completion/Unix/Type/_ps1234 | 14 +++++-- 2 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 Completion/Unix/Type/_date_formats diff --git a/Completion/Unix/Type/_date_formats b/Completion/Unix/Type/_date_formats new file mode 100644 index 0000000..3dd2fa5 --- /dev/null +++ b/Completion/Unix/Type/_date_formats @@ -0,0 +1,80 @@ +#autoload + +local -a specs +local exps bs + +if [[ -z $compstate[quote] ]]; then + bs='\' +fi + +false +if [[ $PREFIX == *%(|[-EO]|<->) ]]; then + specs=() + if [[ $PREFIX != *<-> ]]; then + specs+=( + 'a:abbreviated day name' + 'A:full day name' + 'b:abbreviated month name' + 'B:full month name' + 'c:preferred locale date and time' + 'C:2-digit century' + 'd:day of month (01-31)' + 'D:american format month/day/year (%m/%d/%y)' + 'e:day of month ( 1-31)' + 'E:alternate representation' + 'F:ISO 8601 year-month-date (%Y-%m-%d)' + 'G:4-digit ISO 8601 week-based year' + 'g:2-digit ISO 8601 week-based year' + 'h:abbreviated month name' + 'H:hour (00-23)' + 'I:hour (01-12)' + 'j:day of year (001-366)' + 'k:hour ( 1-23)' + 'l:hour ( 1-12)' + 'm:month (01-12)' + 'M:minute (00-59)' + 'n:newline' + 'O:alternative format modifier' + 'p:locale dependent AM/PM' + 'P:lower case locale dependent am/pm' + 'r:locale dependent a.m. or p.m. time (%I:%M:%S %p)' + 'R:24-hour notation time (%H:%M)' + 's:seconds since the epoch' + 'S:seconds (00-60)' + 't:tab' + 'T:24-hour notation with seconds (%H:%M:%S)' + 'u:day of week (1-7, 1=monday)' + 'U:week number of current year, sunday based (00-53)' + 'V:ISO 8601 week number of current year, week 1 has 4 days in current year (01-53)' + 'w:day of week (0-6, 0=sunday)' + 'W:week number of current year, monday based (00-53)' + 'x:locale dependent date representation without time' + 'X:locale dependent time representation without date' + 'y:2-digit year (00-99)' + 'Y:full year' + 'z:UTC offset' + 'Z:timezone name' + '%:A %' + '-:strip leading space or zero (gnu extension)' + ) + if [[ $1 == zsh ]]; then + specs+=( + 'f:day of month (1-31)' + 'K:hour (0-23)' + 'L:hour (0-12)' + ) + fi + fi + if [[ $1 == zsh ]]; then + specs+=( + '.:fractional part of seconds since epoch' + ) + fi + compset -P "*" + _describe -t date-format-specifier 'date format specifier' specs -S '' + _message -e date-format-precision 'precision for %%. (1-6)' +else + _default "$@" + compset -P "*" + _describe -t date-format-specifier 'date format specifier' '(%)' -S '' +fi diff --git a/Completion/Unix/Type/_ps1234 b/Completion/Unix/Type/_ps1234 index 866349f..b9e5166 100644 --- a/Completion/Unix/Type/_ps1234 +++ b/Completion/Unix/Type/_ps1234 @@ -7,7 +7,9 @@ if [[ -z $compstate[quote] ]]; then bs='\' fi -if [[ $PREFIX == *%(-|)<-># ]]; then +if [[ $PREFIX == *%D$bs\{[^($bs\})]# ]]; then + _date_formats zsh +elif [[ $PREFIX == *%(-|)<-># ]]; then specs=( 'm:hostname up to first .' '_:status of parser' @@ -52,7 +54,7 @@ if [[ $PREFIX == *%(-|)<-># ]]; then '*:current time of day, 24-hour format with seconds' 'w:the date in day-dd format' 'W:the date in mm/dd/yy format' - 'D{}:format string like strftime' + 'D{:format string like strftime' 'B:start bold' 'b:stop bold' 'E:clear to end of line' @@ -121,6 +123,12 @@ elif [[ $PREFIX == *%[FK]$bs\{[0-9a-z]# ]]; then _message -e ansi-color-number "number between 0 and $(( $terminfo[colors] - 1 ))" fi else - _describe -t prompt-format-specifier 'prompt format specifier' '(%)' -S '' _default "$@" + specs=(%) + if compset -P "*%D"; then + specs+=(\{) + else + compset -P "*" + fi + _describe -t prompt-format-specifier 'prompt format specifier' specs -S '' fi -- 2.4.0 ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: PATCH: _ps1234, _date_formats: Complete strftime formats for %D{} 2015-07-06 0:36 PATCH: _ps1234, _date_formats: Complete strftime formats for %D{} Mikael Magnusson @ 2015-07-06 11:11 ` Oliver Kiddle 2015-07-06 14:17 ` Mikael Magnusson 2015-07-08 14:02 ` Jun T. 0 siblings, 2 replies; 12+ messages in thread From: Oliver Kiddle @ 2015-07-06 11:11 UTC (permalink / raw) To: zsh-workers Mikael Magnusson wrote: > > PS, my strftime(3) says it handles %E and %O, and it does work with date +%Ey, > but zsh just prints the literal %Ey. Is it handled wrong by us or not > by the libc like the manpage claims? Looking at the source, it seems only - is treated as a modifier. It'd be nice for it to be updated if it can remain portable. > Completion/Unix/Type/_ps1234 | 14 +++++-- Shouldn't this be in Completion/Zsh/Type? > +else > + _default "$@" I really don't think _default is applicable there. The function is only for completing date formats. If the calling function needs that, it should do it itself. If _default is somehow needed, the return status should be considered. > + compset -P "*" > + _describe -t date-format-specifier 'date format specifier' '(%)' -S '' Using _describe to complete just % seems rather overkill. An _wanted would do. However, it'd be better to use a prefix for the % and use compset -P to cut off complete format specifiers or unrelated characters. The patch below does that and adds a case statement to select some OS specific additions. It'd perhaps be nice to complete format specifiers and modifiers with a different tag and description. Oliver diff --git a/Completion/Unix/Type/_date_formats b/Completion/Unix/Type/_date_formats index 3dd2fa5..f9c80c9 100644 --- a/Completion/Unix/Type/_date_formats +++ b/Completion/Unix/Type/_date_formats @@ -1,80 +1,105 @@ #autoload +local flag local -a specs -local exps bs +local -A exclusion -if [[ -z $compstate[quote] ]]; then - bs='\' -fi +exclusion=( + 'E' '[-_^#cCgGxXyY]' + 'O' '[-_^#BdeHImMSuUVwWy]' + '-' '[OEdegHIjklmMSUz]' + '_' '[OEdgHIjmMSUz]' + '0' '[Oekl]' + '^' '[OEaAbBchP]' + '#' '[OEaAbBchpPrXZ]' +) + +compset -P '(%[0-9EO_\\^#-]#[^0-9%EO_\\^#-]|[^%])#' +compset -S '%*' +specs=( + 'a:abbreviated day name' + 'A:full day name' + 'b:abbreviated month name' + 'B:full month name' + 'c:preferred locale date and time' + 'C:2-digit century' + 'd:day of month (01-31)' + 'D:american format month/day/year (%m/%d/%y)' + 'e:day of month ( 1-31)' + 'E:alternate representation' + 'F:ISO 8601 year-month-date (%Y-%m-%d)' + 'G:4-digit ISO 8601 week-based year' + 'g:2-digit ISO 8601 week-based year' + 'h:abbreviated month name' + 'H:hour (00-23)' + 'I:hour (01-12)' + 'j:day of year (001-366)' + 'k:hour ( 1-23)' + 'l:hour ( 1-12)' + 'm:month (01-12)' + 'M:minute (00-59)' + 'n:newline' + 'O:alternative format modifier' + 'p:locale dependent AM/PM' + 'r:locale dependent a.m. or p.m. time (%I:%M:%S %p)' + 'R:24-hour notation time (%H:%M)' + 's:seconds since the epoch' + 'S:seconds (00-60)' + 't:tab' + 'T:24-hour notation with seconds (%H:%M:%S)' + 'u:day of week (1-7, 1=monday)' + 'U:week number of current year, sunday based (00-53)' + 'V:ISO 8601 week number of current year, week 1 has 4 days in current year (01-53)' + 'w:day of week (0-6, 0=sunday)' + 'W:week number of current year, monday based (00-53)' + 'x:locale dependent date representation without time' + 'X:locale dependent time representation without date' + 'y:2-digit year (00-99)' + 'Y:full year' + 'z:UTC offset' + 'Z:timezone name' + '%:A %' +) -false -if [[ $PREFIX == *%(|[-EO]|<->) ]]; then - specs=() - if [[ $PREFIX != *<-> ]]; then +case $OSTYPE in + freebsd*|linux-gnu|solaris2.<11->) specs+=( - 'a:abbreviated day name' - 'A:full day name' - 'b:abbreviated month name' - 'B:full month name' - 'c:preferred locale date and time' - 'C:2-digit century' - 'd:day of month (01-31)' - 'D:american format month/day/year (%m/%d/%y)' - 'e:day of month ( 1-31)' - 'E:alternate representation' - 'F:ISO 8601 year-month-date (%Y-%m-%d)' - 'G:4-digit ISO 8601 week-based year' - 'g:2-digit ISO 8601 week-based year' - 'h:abbreviated month name' - 'H:hour (00-23)' - 'I:hour (01-12)' - 'j:day of year (001-366)' - 'k:hour ( 1-23)' - 'l:hour ( 1-12)' - 'm:month (01-12)' - 'M:minute (00-59)' - 'n:newline' - 'O:alternative format modifier' - 'p:locale dependent AM/PM' - 'P:lower case locale dependent am/pm' - 'r:locale dependent a.m. or p.m. time (%I:%M:%S %p)' - 'R:24-hour notation time (%H:%M)' - 's:seconds since the epoch' - 'S:seconds (00-60)' - 't:tab' - 'T:24-hour notation with seconds (%H:%M:%S)' - 'u:day of week (1-7, 1=monday)' - 'U:week number of current year, sunday based (00-53)' - 'V:ISO 8601 week number of current year, week 1 has 4 days in current year (01-53)' - 'w:day of week (0-6, 0=sunday)' - 'W:week number of current year, monday based (00-53)' - 'x:locale dependent date representation without time' - 'X:locale dependent time representation without date' - 'y:2-digit year (00-99)' - 'Y:full year' - 'z:UTC offset' - 'Z:timezone name' - '%:A %' - '-:strip leading space or zero (gnu extension)' + "-:don't pad numeric values" + '#:swap case of alphabetic characters' + '0:left pad numeric values with zeroes' + '^:convert lowercase characters to uppercase' + '_:left pad numeric values with spaces' ) - if [[ $1 == zsh ]]; then - specs+=( - 'f:day of month (1-31)' - 'K:hour (0-23)' - 'L:hour (0-12)' - ) - fi - fi - if [[ $1 == zsh ]]; then + ;| + linux-gnu|solaris2.<11->) specs+=( - '.:fractional part of seconds since epoch' + 'P:lower case locale dependent am/pm' ) - fi - compset -P "*" - _describe -t date-format-specifier 'date format specifier' specs -S '' - _message -e date-format-precision 'precision for %%. (1-6)' -else - _default "$@" - compset -P "*" - _describe -t date-format-specifier 'date format specifier' '(%)' -S '' + ;| + freebsd*) + specs+=( 'v:date in short form (%e-%b-%Y)' ) + ;| + solaris2.<11->|freebsd*) + specs+=( '+:localized representation of date and time' ) + ;; + solaris2.<-10>) + specs=( ${specs:#[EOs]:*} ) + ;; +esac + +if [[ $1 == zsh ]]; then + specs+=( + 'f:day of month (1-31)' + 'K:hour (0-23)' + 'L:hour (0-12)' + '.:fractional part of seconds since epoch' + ) fi + +for flag in ${(s..)PREFIX#%}; do + (( $+exclusion[$flag] )) && specs=( ${(M)specs:#${~exclusion[$flag]}:*} ) +done + +_describe -t date-format-specifier 'date format specifier' specs \ + -p "${(Q)PREFIX:-%}" -S '' +_message -e date-format-precision 'precision for %%. (1-6)' ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: PATCH: _ps1234, _date_formats: Complete strftime formats for %D{} 2015-07-06 11:11 ` Oliver Kiddle @ 2015-07-06 14:17 ` Mikael Magnusson 2015-07-06 14:56 ` Mikael Magnusson 2015-07-08 14:02 ` Jun T. 1 sibling, 1 reply; 12+ messages in thread From: Mikael Magnusson @ 2015-07-06 14:17 UTC (permalink / raw) To: Oliver Kiddle; +Cc: zsh workers On Mon, Jul 6, 2015 at 1:11 PM, Oliver Kiddle <okiddle@yahoo.co.uk> wrote: > Mikael Magnusson wrote: >> >> PS, my strftime(3) says it handles %E and %O, and it does work with date +%Ey, >> but zsh just prints the literal %Ey. Is it handled wrong by us or not >> by the libc like the manpage claims? > > Looking at the source, it seems only - is treated as a modifier. > It'd be nice for it to be updated if it can remain portable. > >> Completion/Unix/Type/_ps1234 | 14 +++++-- > > Shouldn't this be in Completion/Zsh/Type? Possibly, but I figured we could use it for _date too? >> +else >> + _default "$@" > > I really don't think _default is applicable there. The function is only > for completing date formats. If the calling function needs that, it > should do it itself. If _default is somehow needed, the return status > should be considered. For this I just copied what I did in _ps1234, which before these two patches did the compset before calling _default, so it would complete filenames anywhere... but of course you couldn't complete in subdirectories since it compset -P away what you just typed :). I guess it's unlikely to be useful here yeah. >> + compset -P "*" >> + _describe -t date-format-specifier 'date format specifier' '(%)' -S '' > > Using _describe to complete just % seems rather overkill. An _wanted > would do. However, it'd be better to use a prefix for the % and use > compset -P to cut off complete format specifiers or unrelated > characters. The patch below does that and adds a case statement to > select some OS specific additions. > > It'd perhaps be nice to complete format specifiers and modifiers with a > different tag and description. I don't know how most of the things you did work, but as far as I can tell it only breaks one thing; pressing tab after %5 now completes all modifiers instead of just putting in a . since %. is the only one that takes a numeric argument. %- is also handled internally by zsh for some modifiers, so it'll work on any OSTYPE as long as $1 is zsh. I'll commit my patches as they were and then you can modify them. -- Mikael Magnusson ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: PATCH: _ps1234, _date_formats: Complete strftime formats for %D{} 2015-07-06 14:17 ` Mikael Magnusson @ 2015-07-06 14:56 ` Mikael Magnusson 0 siblings, 0 replies; 12+ messages in thread From: Mikael Magnusson @ 2015-07-06 14:56 UTC (permalink / raw) To: Oliver Kiddle; +Cc: zsh workers On Mon, Jul 6, 2015 at 4:17 PM, Mikael Magnusson <mikachu@gmail.com> wrote: > On Mon, Jul 6, 2015 at 1:11 PM, Oliver Kiddle <okiddle@yahoo.co.uk> wrote: >> Mikael Magnusson wrote: >>> >>> PS, my strftime(3) says it handles %E and %O, and it does work with date +%Ey, >>> but zsh just prints the literal %Ey. Is it handled wrong by us or not >>> by the libc like the manpage claims? >> >> Looking at the source, it seems only - is treated as a modifier. >> It'd be nice for it to be updated if it can remain portable. >> >>> + compset -P "*" >>> + _describe -t date-format-specifier 'date format specifier' '(%)' -S '' >> >> Using _describe to complete just % seems rather overkill. An _wanted >> would do. However, it'd be better to use a prefix for the % and use >> compset -P to cut off complete format specifiers or unrelated >> characters. The patch below does that and adds a case statement to >> select some OS specific additions. >> >> It'd perhaps be nice to complete format specifiers and modifiers with a >> different tag and description. > > I don't know how most of the things you did work, but as far as I can > tell it only breaks one thing; pressing tab after %5 now completes all > modifiers instead of just putting in a . since %. is the only one that > takes a numeric argument. %- is also handled internally by zsh for > some modifiers, so it'll work on any OSTYPE as long as $1 is zsh. Oh, I see I didn't read far enough in strftime(3), and only checked behaviour in zsh, not date. This is fun too btw: % print -P %D\{%10A\} %10A % print -P %D\{%9A\} %9A I guess this code could use some overall touchups. It looks like the order of modifiers matter, so for example %-Ey works in date, but %E-y does not. Ah, date has a similar bug: % date +%5Ey 15 % date +%-Ey 15 % date +%-5Ey 15 % date +%5-Ey %5-Ey (the string was already five characters, but it still added extra padding, and didn't expand the number, and if it was expanded, there should be one more space). -- Mikael Magnusson ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: PATCH: _ps1234, _date_formats: Complete strftime formats for %D{} 2015-07-06 11:11 ` Oliver Kiddle 2015-07-06 14:17 ` Mikael Magnusson @ 2015-07-08 14:02 ` Jun T. 2015-07-08 14:42 ` Mikael Magnusson 2015-07-09 12:22 ` Oliver Kiddle 1 sibling, 2 replies; 12+ messages in thread From: Jun T. @ 2015-07-08 14:02 UTC (permalink / raw) To: zsh-workers 2015/07/06 20:11, Oliver Kiddle <okiddle@yahoo.co.uk> wrote: > +exclusion=( > + 'E' '[-_^#cCgGxXyY]' > + 'O' '[-_^#BdeHImMSuUVwWy]' man strftime(3) says: Between the '%' character and the conversion specifier character, an optional flag and field width may be specified. (These precede the E or O modifiers, if present.) Here, the flag is one of - _ 0 ^ #. So Isn't it better to omit the flags - _ ^ # from the exclusion above? ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: PATCH: _ps1234, _date_formats: Complete strftime formats for %D{} 2015-07-08 14:02 ` Jun T. @ 2015-07-08 14:42 ` Mikael Magnusson 2015-07-09 12:17 ` Oliver Kiddle 2015-07-09 12:22 ` Oliver Kiddle 1 sibling, 1 reply; 12+ messages in thread From: Mikael Magnusson @ 2015-07-08 14:42 UTC (permalink / raw) To: Jun T.; +Cc: zsh workers On Wed, Jul 8, 2015 at 4:02 PM, Jun T. <takimoto-j@kba.biglobe.ne.jp> wrote: > > 2015/07/06 20:11, Oliver Kiddle <okiddle@yahoo.co.uk> wrote: > >> +exclusion=( >> + 'E' '[-_^#cCgGxXyY]' >> + 'O' '[-_^#BdeHImMSuUVwWy]' > > man strftime(3) says: > > Between the '%' character and the conversion specifier character, > an optional flag and field width may be specified. (These precede > the E or O modifiers, if present.) > > Here, the flag is one of - _ 0 ^ #. So Isn't it better to omit the > flags - _ ^ # from the exclusion above? I've also just noticed that completion after %D\{%\# and \^ doesn't work, but single-quoted is fine. -- Mikael Magnusson ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: PATCH: _ps1234, _date_formats: Complete strftime formats for %D{} 2015-07-08 14:42 ` Mikael Magnusson @ 2015-07-09 12:17 ` Oliver Kiddle 2015-07-09 13:25 ` Mikael Magnusson 2015-07-09 13:53 ` Mikael Magnusson 0 siblings, 2 replies; 12+ messages in thread From: Oliver Kiddle @ 2015-07-09 12:17 UTC (permalink / raw) To: zsh workers Mikael Magnusson wrote: > > I've also just noticed that completion after %D\{%\# and \^ doesn't > work, but single-quoted is fine. That's the fault of _ps1234. It's best to use compset -P and get to a point where _date_formats is called with $PREFIX only containing date formats and no prompt stuff. I finally worked out that the point of calling _default from _ps1234 is for print -P. That's _print's job to do that. This patch also fixes and improves other things like the positioning of numeric arguments for ternary expressions. > >> Completion/Unix/Type/_ps1234 | 14 +++++-- > > Shouldn't this be in Completion/Zsh/Type? > Possibly, but I figured we could use it for _date too? I meant _ps1234 not _date_formats. I'll move it when applying this patch. Oliver diff --git a/Completion/Unix/Type/_ps1234 b/Completion/Unix/Type/_ps1234 index b9e5166..8d3c5d8 100644 --- a/Completion/Unix/Type/_ps1234 +++ b/Completion/Unix/Type/_ps1234 @@ -1,82 +1,58 @@ #compdef -value-,PROMPT,-default- -value-,PROMPT2,-default- -value-,PROMPT3,-default- -value-,PROMPT4,-default- -value-,RPROMPT,-default- -value-,RPROMPT2,-default- -value-,PS1,-default- -value-,PS2,-default- -value-,PS3,-default- -value-,PS4,-default- -value-,RPS1,-default- -value-,RPS2,-default- -value-,SPROMPT,-default- local -a specs -local expl bs +local expl bs suf pre changed=1 ret=1 if [[ -z $compstate[quote] ]]; then - bs='\' + bs='\' # in patterns we use (\\|) widely as print -P handles backslashes first fi -if [[ $PREFIX == *%D$bs\{[^($bs\})]# ]]; then - _date_formats zsh -elif [[ $PREFIX == *%(-|)<-># ]]; then +# first strip off any complete prompt specifications leaving only the +# current, incomplete, one +while (( changed )); do + changed=0 + 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 '[^%]##' && changed=1 # sundry other characters + # %D/%F/%K without a following { ... } + [[ $PREFIX = %(-|)<->#[DFK](\\|)[^{\\]* ]] && + compset -P '%[0-9\\-]#[DFK]' && changed=1 +done +[[ $PREFIX = %(-|)<->[FK](#e) ]] && compset -P '*' # F/K with number + +if compset -P '%[FK]'; then + # this should use -P but that somehow causes single quotes to be stripped + compset -P '(\\|){' || pre=( -p "$bs{" ) + compset -S '(\\|)}*' || suf=( -S $bs\} ) specs=( - 'm:hostname up to first .' - '_:status of parser' - 'd:current working directory' - '/:current working directory' - '~:current working directory, with ~ replacement' - 'N:name of current script or shell function' - 'x:name of file containing code being executed' - 'c:deprecated' - '.:deprecated' - 'C:deprecated' - 'F:start using fg color' - 'K:start using bg color' - 'G:counts as extra character inside %{...%}' + black + red + green + yellow + blue + magenta + cyan + white + default ) - if [[ $PREFIX == *% ]]; then - if [[ $service == -value-,SPROMPT,* ]]; then - specs+=( - 'r:suggested correction' - 'R:corrected string' - ) - fi - specs+=( - '%:A %' - '):A )' - 'l:current line (tty) with /dev/tty stripped' - 'M:full hostname' - 'n:username' - 'y:current line (tty)' - '#:a # when root, % otherwise' - '?:return status of last command' - 'h:current history event number' - '!:current history event number' - 'i:current line number' - 'I:current source line number' - 'j:number of jobs' - 'L:$SHLVL' - 'D:date in yy-mm-dd format' - 'T:current time of day, 24-hour format' - 't:current time of day, 12-hour am/pm format' - '@:current time of day, 12-hour am/pm format' - '*:current time of day, 24-hour format with seconds' - 'w:the date in day-dd format' - 'W:the date in mm/dd/yy format' - 'D{:format string like strftime' - 'B:start bold' - 'b:stop bold' - 'E:clear to end of line' - 'U:start underline' - 'u:stop underline' - 'S:start standout' - 's:stop standout' - 'f:reset fg color' - 'k:reset bg color' - '{:start literal escape sequence' - '}:stop literal escape sequence' - 'v:value from $psvar array' - '(:ternary expression %(x.true-string.false-string)' - '<<:truncation from left %len<string<' - '>>:truncation from right %len>string>' - '[]:truncation from who knows where' - ) + _wanted ansi-colors expl 'ansi color' compadd $suf $pre -a specs && ret=0 + if (( $#suf )) && compset -P "<->"; then + _wanted ansi-colors expl 'closing brace' compadd -S '' \} && ret=0 + else + _message -e terminal-colors "number between 0 and $(( $terminfo[colors] - 1 ))" fi - compset -P "*" - _describe -t prompt-format-specifier 'prompt format specifier' specs -S '' - _message -e prompt-format-specifier number -elif [[ $PREFIX == *%$bs\((-|)<-># ]]; then +fi + +if compset -P '%[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 + compset -S '[.:+/-%]*' || suf=( -S . ) + compset -S '*' specs=( '!:running with privileges' '#:effective uid' @@ -100,35 +76,82 @@ elif [[ $PREFIX == *%$bs\((-|)<-># ]]; then 'V:element n of psvar is set and non-empty' 'w:day of week (Sunday = 0)' ) - compset -P "*" - _describe -t ternary-prompt-expression 'ternary prompt format test character' specs -S '' - _message -e ternary-prompt-expression number -elif [[ $PREFIX == *%[FK]$bs\{[0-9a-z]# ]]; then + _describe -t ternary-prompt-expressions 'ternary prompt format test character' specs $suf && ret=0 +elif compset -P '%D(\\|){'; then + compset -S '(\\|)}*' + _date_formats zsh && ret=0 +elif [[ -prefix '%' ]] || + ! zstyle -t ":completion:${curcontext}:prompt-format-specifiers" prefix-needed +then specs=( - black - red - green - yellow - blue - magenta - cyan - white - default + 'm:hostname up to first .' + '_:status of parser' + '^:reversed status of parser' + 'd:current working directory' + '/:current working directory' + '~:current working directory, with ~ replacement' + 'N:name of current script or shell function' + 'x:name of file containing code being executed' + 'c:deprecated' + '.:deprecated' + 'C:deprecated' + 'F:start using fg color' + 'K:start using bg color' + 'G:counts as extra character inside %{...%}' + '(:ternary expression %(x.true-string.false-string)' ) - compset -P "*{" - _describe -t ansi-color-name 'ansi color' specs -S $bs\} - if compset -P "<->"; then - _wanted ansi-color-number expl 'close brace' compadd -S '' \} - else - _message -e ansi-color-number "number between 0 and $(( $terminfo[colors] - 1 ))" - fi -else - _default "$@" - specs=(%) - if compset -P "*%D"; then - specs+=(\{) - else - compset -P "*" + compset -P '%' || pre=( -p '%' ) + if ! compset -P '(-|)<->'; then + if [[ $service == -value-,SPROMPT,* ]]; then + specs+=( + 'r:suggested correction' + 'R:corrected string' + ) + fi + specs+=( + '%:A %' + '):A )' + 'l:current line (tty) with /dev/tty stripped' + 'M:full hostname' + 'n:username' + 'y:current line (tty)' + '#:a # when root, % otherwise' + '?:return status of last command' + 'h:current history event number' + '!:current history event number' + 'i:current line number' + 'I:current source line number' + 'j:number of jobs' + 'L:$SHLVL' + 'D:date in yy-mm-dd format' + 'T:current time of day, 24-hour format' + 't:current time of day, 12-hour am/pm format' + '@:current time of day, 12-hour am/pm format' + '*:current time of day, 24-hour format with seconds' + 'w:the date in day-dd format' + 'W:the date in mm/dd/yy format' + 'D{:format string like strftime' + 'B:start bold' + 'b:stop bold' + 'E:clear to end of line' + 'U:start underline' + 'u:stop underline' + 'S:start standout' + 's:stop standout' + 'f:reset fg color' + 'k:reset bg color' + '{:start literal escape sequence' + '}:stop literal escape sequence' + 'v:value from $psvar array' + '<:truncation from left %len<string<' + '>:truncation from right %len>string>' + '[:truncation from who knows where' + ) fi - _describe -t prompt-format-specifier 'prompt format specifier' specs -S '' + _describe -t prompt-format-specifiers 'prompt format specifier' \ + specs -S '' $pre && ret=0 + (( ! $#pre )) && [[ -prefix '(-|)<->' ]] && + _message -e prompt-format-specifiers number fi + +return ret diff --git a/Completion/Zsh/Command/_print b/Completion/Zsh/Command/_print index 4053933..1eba13e 100644 --- a/Completion/Zsh/Command/_print +++ b/Completion/Zsh/Command/_print @@ -11,7 +11,7 @@ if [[ $service = print ]]; then pflag='(-s -u -z)-p[print arguments to input of coprocess]' if [[ -n ${words[1,CURRENT][(r)-*P*]} ]]; then - rest='*: :_ps1234' + rest='*: :->prompt' else rest='*: :_default' fi @@ -48,16 +48,17 @@ if [[ $state = printf ]]; then fi if [[ $state = printfformat ]]; then - if [[ ${(Q)PREFIX} = *%((-|)<->|[-#0 +*.])# ]]; then + if [[ ${(Q)PREFIX} = *%[0-9\$#\ +*.\'-]# ]]; then local -a specs specs=( '#:alternate form' - '0:zeropad to length n' + '0:zero pad to length' '-:left adjust result' ' :leave one space in front of positive number from signed conversion' '+:always place sign before a number from signed conversion' '*:field width in next argument' '.:precision' + "':thousand separators" 'c:print the first character of the argument' 's:print the argument as a string' {d,i}':signed decimal number or with leading " numeric value of following character' @@ -73,12 +74,16 @@ if [[ $state = printfformat ]]; then 'q:as %s but shell quote result' ) compset -P "*" - _describe -t print-format-specifier 'print format specifier' specs -S '' - _message -e print-format-specifier 'number' + _describe -t print-format-specifiers 'print format specifier' specs -S '' + _message -e print-format-specifiers 'number' else - _describe -t print-format-specifier 'print format specifier' '(%)' -S '' + _wanted print-format-specifiers expl 'print format specifier' compadd -S '' % fi ret=0 +elif [[ $state = prompt ]]; then + _default && ret=0 + # complete prompt specifiers without interfering too much with default completion + (( $#compstate[unambiguous] <= $#PREFIX || ! $#PREFIX )) && _ps1234 && ret=0 fi return ret ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: PATCH: _ps1234, _date_formats: Complete strftime formats for %D{} 2015-07-09 12:17 ` Oliver Kiddle @ 2015-07-09 13:25 ` Mikael Magnusson 2015-07-09 13:53 ` Mikael Magnusson 1 sibling, 0 replies; 12+ messages in thread From: Mikael Magnusson @ 2015-07-09 13:25 UTC (permalink / raw) To: Oliver Kiddle; +Cc: zsh workers On Thu, Jul 9, 2015 at 2:17 PM, Oliver Kiddle <okiddle@yahoo.co.uk> wrote: > Mikael Magnusson wrote: >> >> I've also just noticed that completion after %D\{%\# and \^ doesn't >> work, but single-quoted is fine. > > That's the fault of _ps1234. > > It's best to use compset -P and get to a point where _date_formats is > called with $PREFIX only containing date formats and no prompt stuff. > > I finally worked out that the point of calling _default from _ps1234 is > for print -P. That's _print's job to do that. It was also so that nobody (weird?) would complain that PS1=/foo<tab> stopped working, I think. > + compset -P '(\\|){' || pre=( -p "$bs{" ) > + compset -S '(\\|)}*' || suf=( -S $bs\} ) Did you mean both $bs and \ here? You probably did, but doesn't hurt to check :). -- Mikael Magnusson ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: PATCH: _ps1234, _date_formats: Complete strftime formats for %D{} 2015-07-09 12:17 ` Oliver Kiddle 2015-07-09 13:25 ` Mikael Magnusson @ 2015-07-09 13:53 ` Mikael Magnusson 2015-07-09 15:20 ` Oliver Kiddle 1 sibling, 1 reply; 12+ messages in thread From: Mikael Magnusson @ 2015-07-09 13:53 UTC (permalink / raw) To: Oliver Kiddle; +Cc: zsh workers On Thu, Jul 9, 2015 at 2:17 PM, Oliver Kiddle <okiddle@yahoo.co.uk> wrote: > This patch also fixes and improves other things like the positioning of > numeric arguments for ternary expressions. 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 :). 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. if [[ -z $compstate[quote] ]]; then bs='\' # in patterns we use (\\|) widely as print -P handles backslashes first fi I find the placement of this comment a bit odd, $bs is about accepting/putting a backslash in places where the parser wants, not any backslashes that print ever sees. Let's hope nobody ever tries to use print -rP. -- Mikael Magnusson ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: PATCH: _ps1234, _date_formats: Complete strftime formats for %D{} 2015-07-09 13:53 ` Mikael Magnusson @ 2015-07-09 15:20 ` Oliver Kiddle 2015-07-09 23:02 ` Oliver Kiddle 0 siblings, 1 reply; 12+ messages in thread From: Oliver Kiddle @ 2015-07-09 15:20 UTC (permalink / raw) To: zsh workers 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 ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: PATCH: _ps1234, _date_formats: Complete strftime formats for %D{} 2015-07-09 15:20 ` Oliver Kiddle @ 2015-07-09 23:02 ` Oliver Kiddle 0 siblings, 0 replies; 12+ messages in thread From: Oliver Kiddle @ 2015-07-09 23:02 UTC (permalink / raw) To: zsh workers We normally leave configuration of colours for complist to the users but in the case of the completion of terminal colours, I think the following is useful. It is also one situation where we don't need to worry about the user's colour preferences or even whether a particular colour is visible over their background. Any thoughts? I think the description of "ANSI" is only applicable to the first 8 (or 16 colours), right? This hasn't allowed for custom configuration of the lc and rc in _comp_colors. Anyone know if there is a particular layout of rows/columns that should be used so the colours line up logically? Should we use set the background colour instead when completing within %K{...}? (it seemed uglier to me). Oliver diff --git a/Completion/Zsh/Type/_ps1234 b/Completion/Zsh/Type/_ps1234 index f182a16..de4ecb2 100644 --- a/Completion/Zsh/Type/_ps1234 +++ b/Completion/Zsh/Type/_ps1234 @@ -1,7 +1,8 @@ #compdef -value-,PROMPT,-default- -value-,PROMPT2,-default- -value-,PROMPT3,-default- -value-,PROMPT4,-default- -value-,RPROMPT,-default- -value-,RPROMPT2,-default- -value-,PS1,-default- -value-,PS2,-default- -value-,PS3,-default- -value-,PS4,-default- -value-,RPS1,-default- -value-,RPS2,-default- -value-,SPROMPT,-default- local -a specs -local expl bs suf pre changed=1 ret=1 +local expl grp cols bs suf pre changed=1 ret=1 +local -A ansi [[ -z $compstate[quote] ]] && bs='\' @@ -22,24 +23,37 @@ done if compset -P '%[FK]'; then # this should use -P but that somehow causes single quotes to be stripped - compset -P '(\\|){' || pre=( -p "$bs{" ) - compset -S '(\\|)}*' || suf=( -S $bs\} ) - specs=( - black - red - green - yellow - blue - magenta - cyan - white - default + compset -P '(\\|){' || pre=( -p '{' ) + compset -S '(\\|)}*' || suf=( -S "$bs}" ) + ansi=( + black 30 + red 31 + green 32 + yellow 33 + blue 34 + magenta 35 + cyan 36 + white 37 + default 39 ) - _wanted ansi-colors expl 'ansi color' compadd $suf $pre -a specs && ret=0 - if (( $#suf )) && compset -P "<->"; then + + _description -V ansi-colors expl 'ansi color' + grp="$expl[expl[(i)-V]+1]" + _comp_colors+=( ${(ps.\0.)"$(printf "($grp)=%s=%s\0" ${(kv)ansi})"} ) + compadd "$expl[@]" $suf $pre -k ansi && ret=0 + if (( $#suf )) && compset -P "(<->|%v)"; then _wanted ansi-colors expl 'closing brace' compadd -S '' \} && ret=0 + elif (( $+terminfo[colors] )); then + (( cols = $terminfo[colors] - 1 )) + (( cols = cols > 255 ? 255 : cols )) + _description -V terminal-colors expl 'terminal color' + grp="$expl[expl[(i)-V]+1]" + compadd "$expl[@]" $suf $pre {0..$cols} + for c in {0..$cols}; do + _comp_colors+=( "($grp)=${c}=${${$(print -P "%F{$c}")#?\[}%m}" ) + done else - _message -e terminal-colors "number between 0 and $(( $terminfo[colors] - 1 ))" + _message -e terminal-colors "number" fi fi ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: PATCH: _ps1234, _date_formats: Complete strftime formats for %D{} 2015-07-08 14:02 ` Jun T. 2015-07-08 14:42 ` Mikael Magnusson @ 2015-07-09 12:22 ` Oliver Kiddle 1 sibling, 0 replies; 12+ messages in thread From: Oliver Kiddle @ 2015-07-09 12:22 UTC (permalink / raw) To: zsh-workers "Jun T." wrote: > man strftime(3) says: > > Between the '%' character and the conversion specifier character, > an optional flag and field width may be specified. (These precede > the E or O modifiers, if present.) > > Here, the flag is one of - _ 0 ^ #. So Isn't it better to omit the > flags - _ ^ # from the exclusion above? Good point, thanks. I hadn't noticed that there was a distinction between the flags and modifiers. Oliver diff --git a/Completion/Unix/Type/_date_formats b/Completion/Unix/Type/_date_formats index 2daf820..09f8cab 100644 --- a/Completion/Unix/Type/_date_formats +++ b/Completion/Unix/Type/_date_formats @@ -5,8 +5,8 @@ local -aU specs local -A exclusion exclusion=( - 'E' '[-_^#cCgGxXyY]' - 'O' '[-_^#BdeHImMSuUVwWy]' + 'E' '[cCgGxXyY]' + 'O' '[BdeHImMSuUVwWy]' '-' '[OEdegHIjklmMSUz]' '_' '[OEdgHIjmMSUz]' '0' '[Oekl]' ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2015-07-09 23:09 UTC | newest] Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-07-06 0:36 PATCH: _ps1234, _date_formats: Complete strftime formats for %D{} Mikael Magnusson 2015-07-06 11:11 ` Oliver Kiddle 2015-07-06 14:17 ` Mikael Magnusson 2015-07-06 14:56 ` Mikael Magnusson 2015-07-08 14:02 ` Jun T. 2015-07-08 14:42 ` Mikael Magnusson 2015-07-09 12:17 ` Oliver Kiddle 2015-07-09 13:25 ` Mikael Magnusson 2015-07-09 13:53 ` Mikael Magnusson 2015-07-09 15:20 ` Oliver Kiddle 2015-07-09 23:02 ` Oliver Kiddle 2015-07-09 12:22 ` Oliver Kiddle
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).