bug-bash
[Top][All Lists]
Advanced

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

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


From: Koichi Murase
Subject: Re: [PATCH] Save more readline state when running compgen
Date: Wed, 22 Mar 2023 08:00:01 +0900

2023年3月22日(水) 6:00 Greg Wooledge <greg@wooledge.org>:
> I don't use programmable completion, but I could *imagine* someone using
> a temp file to store the results, then using mapfile to read them back
> in, to avoid the fork() that the command substitution uses.

I wouldn't say my usage is typical, but I do that in fact. I have a
shell function to do that for an arbitrary command (which I once
posted in help-bash [1] but now it's old. The latest is [2]) and use
it everywhere.

[1] https://lists.gnu.org/archive/html/help-bash/2020-05/msg00057.html
[2] https://github.com/akinomyoga/ble.sh/blob/2eadcd5b/src/util.sh#L2173-L2225

> You'd
> need a non-forking way to create the temp file, and to remove it, though,
> or you'll lose all your gains in those steps.

Yes, there is no gain for the temp file If we are going to do that
only once. But if we are going to use it repeatedly in one interactive
session or in a single execution of a Bash program, we can obtain
gains because we can create the temporary file only once at the
beginning of the session/program (of course with appropriate
permissions, etc.). Of course, the temporary file should be cleaned up
later by using the EXIT trap or another way.

[3] https://github.com/akinomyoga/ble.sh/blob/2eadcd5b/ble.pp#L1346-L1486
(creation of a tempdir)
[4] https://github.com/akinomyoga/ble.sh/blob/2eadcd5b/ble.pp#L1501-L1551
(cleanup)

----

But I also sometimes utilize `compgen' for purposes unrelated to
completions. For example, when I want to check the list of Bash
versions installed in my system, I would directly run

$ compgen -c bash

in the command line. Another usage is to filter array elements by «
compgen -W '"${arr[@]}"' -X '...' » (assuming the array elements do
not contain newlines), which can be combined with the temporary-file
the approach mentioned above.

--
Koichi



reply via email to

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