[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Save more readline state when running compgen

From: Grisha Levit
Subject: Re: [PATCH] Save more readline state when running compgen
Date: Tue, 21 Mar 2023 17:42:04 -0400

On Tue, Mar 21, 2023 at 5:26 PM alex xmb ratchev <fxmbsw7@gmail.com> wrote:
> On Tue, Mar 21, 2023, 21:05 Grisha Levit <grishalevit@gmail.com> wrote:
>> compgen -G 'foo/*' >/dev/null && COMPREPLY=(bar)
> i dont get that code at all , but i like idea of speedier file filling .. can 
> u explain some in short ?

Let's say you want to know if there are any entries starting with
`foo' in the current directory.  You can do:

shopt -s nullglob
set +o noglob
if (( ${#tmp[@]} )); then ...

Or you can do

if compgen -G 'foo*' >/dev/null; then ...

The latter doesn't care about nullglob / noglob / GLOBIGNORE and if
the number of files is large can be a lot faster.

P.S. If you are interested in files that may or may not start with a
dot, you do need to set dotglob in either case, which was the
motivation for https://lists.gnu.org/archive/html/bug-bash/2023-03/msg00062.html

reply via email to

[Prev in Thread] Current Thread [Next in Thread]