From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22598 invoked by alias); 6 Jul 2015 11:18:22 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 35700 Received: (qmail 15425 invoked from network); 6 Jul 2015 11:18:19 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1436181111; bh=58RbBkkCwPLlq2oylaDQnppu7tcBsv/fwvaqUeIPA6Q=; h=In-reply-to:From:References:To:Subject:Date:From:Subject; b=OpQKon8ECfr+xflgwpYZbfDE81aY8wUjANCggryMIVrh+fgBIvao8rdQW2rqXeHgT/cX7gCwlFM0qLNuy4GzHYgujPvADleGDcfr4mSnwKAWbZuP6EdmSV60foFb0Tc9Kv6J56Clap8JzDkQcCEejTsG0CjUS9rI08ASPXqjEg4T3BclMX+8ER/PXnp+bqk2zUJeV6P1X7EBIJ0/WL9ooANoqCE6SOMV65+k46Mayy2vl2QlwIv1byNe5JxhXgIuAa89UTwbXkV9C7NGqa+iI7FrOnaYm3wVmwmQBkEi+wu3LbmUSLoU1GiTEpKp3jgDuAIp9TTAWXtgZjSOGDWZ4Q== X-Yahoo-Newman-Id: 546935.82499.bm@smtp146.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: a5Wv9nMVM1mTYfSb3GOYwYiTSY1Qr8E0ZfhwYYnxr_7dU99 dUnX103WzFihSFY2YgnX.xsyS.HsragECCW2ZEUeh5_cr057CoRT6DqllAc9 Vh_vuIBM27m2VU9sRB87y_TDI0kHUmCug31islYkS2So0f4Avbacnm8rtjYc XvPTG48.KiR8HLxLh4pregOOursRxuJy88lizm46ABraaPJX1dGx2Z49FrG4 ikZafUJXX3D3SwBBh1RAlR3nrJ39Q_BQVLC800BXp5Dzujv1RRpUHmn13SGy VWmGk.qcQVNYXF4HPZRujpXK.wWCa4RSXVV5UtFfehnoEOFtPInxFSXdTx6b Sr4VXkJIqRvRA1uRLeW2CnaY9Ur3CI0BgC3bTuk1YxI6BQA8s81ybnwU2u6g mWo581rMPpFANt8b9Zp8pHe6_CJyZIp57a.TjoK3uw8HD_9ZEa4TlabHN6ad hgHj97VdPWtQqhGASkJbJRnfoprj0Ay1p_vihUxXgv_aKcCQ8dMc8CO2LSyv 5jWc1CNBag9KpIcSHhaxTFChNhyvOZA-- X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI- In-reply-to: <1436143012-9243-1-git-send-email-mikachu@gmail.com> From: Oliver Kiddle References: <1436143012-9243-1-git-send-email-mikachu@gmail.com> To: zsh-workers@zsh.org Subject: Re: PATCH: _ps1234, _date_formats: Complete strftime formats for %D{} MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4739.1436181110.1@thecus.kiddle.eu> Date: Mon, 06 Jul 2015 13:11:50 +0200 Message-ID: <4740.1436181110@thecus.kiddle.eu> 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)'