zsh-workers
 help / color / mirror / code / Atom feed
* _time_zone gives me candidates other than timezones
@ 2022-03-24 18:36 Jordan Russell
  2022-03-29 23:22 ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Jordan Russell @ 2022-03-24 18:36 UTC (permalink / raw)
  To: zsh-workers

Hello,

I am writing a completion function and I want it to complete
timezones. zsh has the builtin _time_zone completion function for this,
but when I use it I get filenames that are not timezones like
`iso3166.tab`, `leap-seconds.list` and `zone1970.tab`. These are all
files that live in my /usr/share/zoneinfo directory and are a part of my
distribution's `tzdata` package.

I would like _time_zone to exclude these filenames that are not
timezones. I looked at the _time_zone function with `which _time_zone`
after it was loaded and got

_time_zone () {
	local expl
	if (( ! $+_zoneinfo_dirs ))
	then
		_zoneinfo_dirs=(/usr/{share,lib,share/lib}/{zoneinfo*,locale/TZ}(/)) 
	fi
	_wanted time-zones expl 'time zone' _files -W _zoneinfo_dirs "$@" -
}

If I modify it to just exclude those files that begin with a lowercase
letter then it gives me only proper timezone names. I added `-F
([a-z]*)"` in the call to `_wanted` and it seems to do what I want.

I've included a patch for this small change. Whether or not the change
is acceptable or not comes down to whether or not it works to do what it
purports to do and also whether or not _time_zone was supposed to return
things like the timezone.tab files in the first place.

diff --git a/Completion/Unix/Type/_time_zone b/Completion/Unix/Type/_time_zone
index cd924bb..c9442eb 100644
--- a/Completion/Unix/Type/_time_zone
+++ b/Completion/Unix/Type/_time_zone
@@ -6,4 +6,4 @@ if (( ! $+_zoneinfo_dirs )); then
   _zoneinfo_dirs=( /usr/{share,lib,share/lib}/{zoneinfo*,locale/TZ}(/) )
 fi
 
-_wanted time-zones expl 'time zone' _files -W _zoneinfo_dirs "$@" -
+_wanted time-zones expl 'time zone' _files -W _zoneinfo_dirs -F "([a-z]*)" "$@" -


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: _time_zone gives me candidates other than timezones
  2022-03-24 18:36 _time_zone gives me candidates other than timezones Jordan Russell
@ 2022-03-29 23:22 ` Bart Schaefer
  2022-03-30  0:12   ` Aaron Schrab
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2022-03-29 23:22 UTC (permalink / raw)
  To: Jordan Russell; +Cc: Zsh hackers list

On Thu, Mar 24, 2022 at 12:28 PM Jordan Russell
<jordan.likes.curry@gmail.com> wrote:
>
> I would like _time_zone to exclude these filenames that are not
> timezones [...]
>
> If I modify it to just exclude those files that begin with a lowercase
> letter then it gives me only proper timezone names.

That excludes the directories "posix" and "right" on my system (I have
no idea what the latter one means).

Is everyone OK with that?


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: _time_zone gives me candidates other than timezones
  2022-03-29 23:22 ` Bart Schaefer
@ 2022-03-30  0:12   ` Aaron Schrab
  2022-03-31 15:25     ` Jun. T
  0 siblings, 1 reply; 7+ messages in thread
From: Aaron Schrab @ 2022-03-30  0:12 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Jordan Russell, Zsh hackers list

At 16:22 -0700 29 Mar 2022, Bart Schaefer <schaefer@brasslantern.com> wrote:
>On Thu, Mar 24, 2022 at 12:28 PM Jordan Russell
><jordan.likes.curry@gmail.com> wrote:
>>
>> I would like _time_zone to exclude these filenames that are not
>> timezones [...]
>>
>> If I modify it to just exclude those files that begin with a lowercase
>> letter then it gives me only proper timezone names.
>
>That excludes the directories "posix" and "right" on my system (I have
>no idea what the latter one means).

Quoting from https://www.ucolick.org/~sla/leapsecs/right+gps.html:

    The "right" files in the tz (zoneinfo) database have a subtle 
    difference from the POSIX standard. POSIX requires that the system 
    clock value of time_t represent the number of non-leap seconds since 
    1970-01-01. This is the same as requiring POSIX seconds to be mean 
    solar seconds of UT, not the atomic seconds that UTC has counted 
    since 1972-01-01.

   The "right" zoneinfo files assert that the system clock value of 
   time_t represent the actual number of seconds in the internationally 
   approved broadcast time scale since 1970-01-01. As a result the value 
   of time_t which is expected by the "right" zoneinfo files is greater 
   than the value of time_t specified by POSIX. The difference in the 
   values of time_t is the number of leap seconds which have been 
   inserted into the internationally approved broadcast time scale. As of 
   year 2011 the difference is 24 seconds. 

I'm a bit more puzzled about why the separate `posix` directory exists. 
At least for my local time zone it doesn't seem to matter if I use that 
or leave it out; while using the `right` one definitely makes a 
difference:

date; TZ=right/America/New_York date; TZ=posix/America/New_York date
2022-03-29T20:07:47 EDT
2022-03-29T20:07:20 EDT
2022-03-29T20:07:47 EDT

>Is everyone OK with that?

While I don't think I've ever really needed to use zoneinfo entries from 
those directories, I'd certainly prefer they be offered for completion.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: _time_zone gives me candidates other than timezones
  2022-03-30  0:12   ` Aaron Schrab
@ 2022-03-31 15:25     ` Jun. T
  2022-04-05 23:18       ` Jordan Russell
  0 siblings, 1 reply; 7+ messages in thread
From: Jun. T @ 2022-03-31 15:25 UTC (permalink / raw)
  To: zsh-workers


> 2022/03/30 9:12, Aaron Schrab <aaron@schrab.com> wrote:
> 
> While I don't think I've ever really needed to use zoneinfo entries from those directories, I'd certainly prefer they be offered for completion.

How about this?

diff --git a/Completion/Unix/Type/_time_zone b/Completion/Unix/Type/_time_zone
index cd924bbc7..c437252a8 100644
--- a/Completion/Unix/Type/_time_zone
+++ b/Completion/Unix/Type/_time_zone
@@ -6,4 +6,4 @@ if (( ! $+_zoneinfo_dirs )); then
   _zoneinfo_dirs=( /usr/{share,lib,share/lib}/{zoneinfo*,locale/TZ}(/) )
 fi
 
-_wanted time-zones expl 'time zone' _files -W _zoneinfo_dirs "$@" -
+_wanted time-zones expl 'time zone' _files -g '[A-Z]*' -W _zoneinfo_dirs "$@" -





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: _time_zone gives me candidates other than timezones
  2022-03-31 15:25     ` Jun. T
@ 2022-04-05 23:18       ` Jordan Russell
  2022-04-06 20:11         ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Jordan Russell @ 2022-04-05 23:18 UTC (permalink / raw)
  To: Jun. T; +Cc: zsh-workers

I like Jun's solution. I still have reservations about completing right/
and posix/ (they could be flags instead to the calling program). But the
difference isn't a really big one.

That said I did write a big email about it and I think I only sent it to
Aaron Schrab (sorry). So now I'm quoting it here and actually CC'ing the list

>I guess it comes down to whether you call _time_zone to find a zoneinfo
>/file/ or a timezone /name/.
>
>If you're just completing the name of a timezone then whether the name
>of the timezone refers to a `right` timezone or a `posix` timezone seems
>like it could be better handled by the programmer calling
>_time_zone. After all the names under right/ and posix/ are identical so
>the directory prefix only adds a bit of semantic information, which
>would probably be better handled as an argument somehwere beforehand
>rather than parsed out later.
>
>If you're calling _time_zone to complete zoneinfo files themselves then
>excluding posix/ and right/ is wrong since each directory houses
>different files and so their differences can't be easily accounted for
>otherwise. But if you're completing filenames you'd also need to recover
>the prefix which is lost when using -W as is used now.
>
>> I'm a bit more puzzled about why the separate `posix` directory exists. 
>> At least for my local time zone it doesn't seem to matter if I use that 
>> or leave it out; while using the `right` one definitely makes a 
>> difference:
>Yeah, I get the same behavior on my system.
>
>So, no I wasn't aware of the difference between right/ and posix/ but I
>also don't think their exclusion will matter since I think _time_zone is
>more for completing names by way of files and the files themselves are
>not relevant in this context.
>


"Jun. T" <takimoto-j@kba.biglobe.ne.jp> writes:

>> 2022/03/30 9:12, Aaron Schrab <aaron@schrab.com> wrote:
>> 
>> While I don't think I've ever really needed to use zoneinfo entries from those directories, I'd certainly prefer they be offered for completion.
>
> How about this?
>
> diff --git a/Completion/Unix/Type/_time_zone b/Completion/Unix/Type/_time_zone
> index cd924bbc7..c437252a8 100644
> --- a/Completion/Unix/Type/_time_zone
> +++ b/Completion/Unix/Type/_time_zone
> @@ -6,4 +6,4 @@ if (( ! $+_zoneinfo_dirs )); then
>    _zoneinfo_dirs=( /usr/{share,lib,share/lib}/{zoneinfo*,locale/TZ}(/) )
>  fi
>  
> -_wanted time-zones expl 'time zone' _files -W _zoneinfo_dirs "$@" -
> +_wanted time-zones expl 'time zone' _files -g '[A-Z]*' -W _zoneinfo_dirs "$@" -


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: _time_zone gives me candidates other than timezones
  2022-04-05 23:18       ` Jordan Russell
@ 2022-04-06 20:11         ` Bart Schaefer
  2022-04-08  7:30           ` Jun T
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2022-04-06 20:11 UTC (permalink / raw)
  To: Jordan Russell; +Cc: Jun. T, Zsh hackers list

On Tue, Apr 5, 2022 at 4:19 PM Jordan Russell
<jordan.likes.curry@gmail.com> wrote:
>
> I like Jun's solution.

That's good, because it's already been added to the repository.
However, I did notice that if one explicitly attempts to start a
timezone name with "z" or "l", the lower case file names are in fact
offered (instead of, for example, correcting to Zulu).

> I still have reservations about completing right/
> and posix/ (they could be flags instead to the calling program).

Do you mean the calling program might use those as keywords (with no
leading hyphen[s])?  Or do you mean the caller of _time_zone should
[be able to] specify whether to include them?

> >I guess it comes down to whether you call _time_zone to find a zoneinfo
> >/file/ or a timezone /name/.
[...]
> > But if you're completing filenames you'd also need to recover
> >the prefix which is lost when using -W as is used now.

Further, if you start completing the tail of an absolute path, normal
file completion occurs.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: _time_zone gives me candidates other than timezones
  2022-04-06 20:11         ` Bart Schaefer
@ 2022-04-08  7:30           ` Jun T
  0 siblings, 0 replies; 7+ messages in thread
From: Jun T @ 2022-04-08  7:30 UTC (permalink / raw)
  To: zsh-workers


> 2022/04/07 5:11、Bart Schaefer <schaefer@brasslantern.com>のメール:
> 
> However, I did notice that if one explicitly attempts to start a
> timezone name with "z" or "l", the lower case file names are in fact
> offered (instead of, for example, correcting to Zulu).

Do you mean this?
If there is no time zone file/directoey staring with 'X', but there is
a non-timezone file 'xyz', say, then
TZ=x<TAB>
will still offer xyz.

diff --git a/Completion/Unix/Type/_time_zone b/Completion/Unix/Type/_time_zone
index c437252a8..a7b63adcd 100644
--- a/Completion/Unix/Type/_time_zone
+++ b/Completion/Unix/Type/_time_zone
@@ -6,4 +6,5 @@ if (( ! $+_zoneinfo_dirs )); then
   _zoneinfo_dirs=( /usr/{share,lib,share/lib}/{zoneinfo*,locale/TZ}(/) )
 fi
 
-_wanted time-zones expl 'time zone' _files -g '[A-Z]*' -W _zoneinfo_dirs "$@" -
+_wanted time-zones expl 'time zone' \
+  _files -g '[A-Z]*' -M 'm:{a-z}={A-Z}' -W _zoneinfo_dirs "$@" -






^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-04-08  7:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24 18:36 _time_zone gives me candidates other than timezones Jordan Russell
2022-03-29 23:22 ` Bart Schaefer
2022-03-30  0:12   ` Aaron Schrab
2022-03-31 15:25     ` Jun. T
2022-04-05 23:18       ` Jordan Russell
2022-04-06 20:11         ` Bart Schaefer
2022-04-08  7:30           ` Jun T

Code repositories for project(s) associated with this 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).