79480072

Date: 2025-03-03 02:57:08
Score: 1
Natty:
Report link

I have been struggling with a more general form of the problem. The Python 3.11 code from Kiran N S assumes that whitespace is a delimiter. The problem I am trying to solve is how to get bash-like completion of filenames, dealing with whitespace, quoting, and escapes. So if I have files with names "f 1" and "f 2", then I want

ls "f<tab>

to add a space, and then another to tell me about "f 1" and "f 2". Bash presumably uses readline, but I haven't been able to figure out how to do this through the readline module in Python.

One problem is that I can't see a set of delimiters that is correct in all cases. In this input:

ls "f<space>tab>

the space is not a delimiter, it is part of the text to be completed. But for this input:

ls abc

spaces are delimiters.

I suppose I could parse the line, and modify the tokenizer with delimiters for the input I'm seeing, but that feels wrong to me. And I haven't tried it yet so I don't even know that it's workable. On the other hand, I can't come up with anything better.

Reasons:
  • Blacklisted phrase (1): I am trying to
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Jack Orenstein