zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: zsh-workers@zsh.org
Subject: Re: PATCH: _ps1234, _date_formats: Complete strftime formats for %D{}
Date: Mon, 06 Jul 2015 13:11:50 +0200	[thread overview]
Message-ID: <4740.1436181110@thecus.kiddle.eu> (raw)
In-Reply-To: <1436143012-9243-1-git-send-email-mikachu@gmail.com>

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)'


  reply	other threads:[~2015-07-06 11:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-06  0:36 Mikael Magnusson
2015-07-06 11:11 ` Oliver Kiddle [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4740.1436181110@thecus.kiddle.eu \
    --to=okiddle@yahoo.co.uk \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).