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

Re: WIP _units



Yeah, I wouldn't use [A-z]. Also adding _ to it to get [A-z_] is redundant, because the _ is already included in the A-z range, along with [, \, ], ^, and `.  

 For most applications [[:alnum::]] is best. Of course, it's also locale-dependent; in the C locale it's equivalent to [A-Za-z0-9], but in other locales it can include characters outside the ASCII range. Last I checked, units(1) was ASCII-only (e.g. it uses u- instead of μ- for micro-).

On Thu, Jul 30, 2026 at 7:07 AM Oliver Kiddle <opk@xxxxxxx> wrote:
christopher@xxxxxxxxx wrote:
> i'm trying to update _units to allow completion for e.g. `units area_<TAB>`
> which currently breaks with the underscore. I couldn't make out what i have
> to add to compadd to make this work.
> Any suggestions?

The problem is with the two compset commands early in the function which
try to strip off characters not belonging to the units like numbers. They
are removing `area_` from the completion matching because of the
underscore. Try adding the _ into those patterns too:

  compset -P '*[^[:alnum:]_]'
  compset -S '[^[:alnum:]_]*'

>  testfiles=(
> -  /usr/share/units.dat               # GNU on Fedora

Did you make any actual changes here or is this purely realignment?

On my system, more than one file matches including an extra currency
one. The completion ignores that second file. I can't see why it needs a
loop instead of something like $^testfiles(N) adding also Y1 to the
qualifier if only one should be matched.

> -units=(${${all:#^[[:alnum:]]##([\(\]]*|)}%%\(*})
> +units=(${${all:#^[0-9A-z_]##([\(\]]*|)}%%\(*})

I'd keep the character class rather than use something like A-z which
may include 6 extra ASCII characters, so e.g:

  units=( ${${all:#^[[:alnum:]_]##([\(\]]*|)}%%\(*} )

Oliver



--
Mark J. Reed <markjreed@xxxxxxxxx>


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