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

Re: bash-completion pros/cons



On 18/06/2020 20:15, David Wright wrote:
> On Wed 17 Jun 2020 at 10:04:19 (+0200), Anders Andersson wrote:
>> On Tue, Jun 16, 2020 at 9:48 PM David Wright <deblis@lionunicorn.co.uk> wrote:
>>> Where bash-completion does get in the way for me is, for example,
>>> where you download a file that's, say, a PDF but it arrives via wget
>>> called, say, index_0001.3872359.html, for whatever reason.
>>> So you type   xpdf inde [TAB]   and bash-completion refuses to
>>> complete the name any further. If you're lucky, typing   * [RETURN]
>>> will work, if there aren't any disruptive filenames which match
>>> inde*, but in other cases the fastest workaround I know is to type
>>> [HOME]less[SPACE][END] whereupon bash-completion is happy to match
>>> any old filename for the less command, which you then rub out.
>>>
>>> That's just one example, but it represents a whole class where it
>>> seems that a bunch of files have disappeared because bash won't match them.
>> First time this happened to me (it also happens with buggy
>> completion-scripts where the author doesn't know all the ways to use
>> the tool) I found that bash maps M-/ to "complete-filename" by
>> default. This can be used in all contexts. The only problem is that I
>> always forget the combo.
> Thanks. This is part of man bash that I hadn't visited for too long.
> It probably covers most cases, and I just used it to complete
> xpdf index.html\?id=00000172-c4ea-d07a-a7f7-ccff84da0000
> (which is a PDF of USA v John Bolton just downloaded from Politico).

While magic numbers exist (that is, specific bytes or sequences within a
file which identify the format of a file), opening every file which
matches "ind*", and filtering for just those which are PDFs, DVIs or
whatever other digital paper formats xpdf takes time. It's a *lot*
easier to simply replace ind* with ind*.pdf and discover that there's
only one match.

Arguably, another alternative would be to store the mime type of every
file as metadata associated with the file, but A) there are plenty of
file types which don't have mime types (e.g. applications, libraries and
many proprietary data formats would just be application/octet-stream)
and B) the "file extension" convention is cross-platform, portable and
has existed, virtually unchanged, for nearly half a century.


>
> The only snag (I think) is that, in the presence of a file called,
> say, indolent-45.pdf, typing   xpdf ind [TAB]   will immediately
> complete to xpdf indolent45.pdf without revealing that any other
> ind* files exist (that aren't .pdf files themselves).
> Not of great importance to me, because I normally rename files to
> conform with conventions.
>
> Cheers,
> David.
>

Attachment: signature.asc
Description: OpenPGP digital signature


Reply to: