zsh-workers
 help / color / mirror / code / Atom feed
From: Jordan Russell <jordan.likes.curry@gmail.com>
To: zsh-workers@zsh.org
Subject: _time_zone gives me candidates other than timezones
Date: Thu, 24 Mar 2022 11:36:37 -0700	[thread overview]
Message-ID: <875yo3b3ka.fsf@smokey> (raw)

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


             reply	other threads:[~2022-03-24 19:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-24 18:36 Jordan Russell [this message]
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

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=875yo3b3ka.fsf@smokey \
    --to=jordan.likes.curry@gmail.com \
    --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).