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

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