Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: _ps1234, _date_formats: Complete strftime formats for %D{}
- X-seq: zsh-workers 35697
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: _ps1234, _date_formats: Complete strftime formats for %D{}
- Date: Mon, 6 Jul 2015 02:36:52 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=9WgWdmN6F02aZVo83dRKEAVJfEQS5OKR8+oOsm/Gh0M=; b=KWl45KL05No63gS621umEq9+oKTY8YausEh5bG8qpnLT++x66eIfdxXU9vv4wzeGdB bgsl46aKzSo0ra/x3UW475JknV6nGib2+BVHLRuEUr/Jmx7vnqzxkCOsXrzmLkRqbrvF bw3ZbV6xpUtvbFgZESS+pIzy227M/dfHC6DGnnFKhe1DyJqWYhlH8qtppiXD5tgs3pZ3 s4ZZksvWR0SFbJYkXQ4ROHMrYNTZYfv7DT7vbnuafyppyhGZz1mSP0zHBvkJkUkXSE/T 37723G/gp+potL9UAsY8PPcg6Tz89W13qae/4EKtiVF/ethpahq15rohk/cIMwcjVniH TBvQ==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author