Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

_time_zone gives me candidates other than timezones



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]*)" "$@" -




Messages sorted by: Reverse Date, Date, Thread, Author