Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit b13f4a9

Browse files
authored
Merge pull request #13 from jmcrawford45/fix-lprefix-computation
Fix and test with xonsh glob expansion
2 parents e39ccfa + a82ad40 commit b13f4a9

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

bash_completion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def bash_completions(prefix, line, begidx, endidx, env=None, paths=None,
346346
strip_len = 0
347347
strip_prefix = prefix.strip("\"'")
348348
while strip_len < len(prefix):
349-
if commprefix.startswith(strip_prefix[strip_len:]):
349+
if commprefix[strip_len] == strip_prefix[strip_len]:
350350
break
351351
strip_len += 1
352352

news/fix-lprefix-computation.rst

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
**Added:** None
2+
3+
**Changed:** None
4+
5+
**Deprecated:** None
6+
7+
**Removed:** None
8+
9+
**Fixed:**
10+
11+
* bash_completions to include special characters in lprefix
12+
13+
Previously, glob expansion characters would not be included in lprefix for replacement
14+
15+
.. code-block:: sh
16+
17+
$ touch /tmp/abc
18+
$ python
19+
>>> from bash_completion import bash_completions
20+
>>>
21+
>>> def get_completions(line):
22+
... split = line.split()
23+
... if len(split) > 1 and not line.endswith(' '):
24+
... prefix = split[-1]
25+
... begidx = len(line.rsplit(prefix)[0])
26+
... else:
27+
... prefix = ''
28+
... begidx = len(line)
29+
... endidx = len(line)
30+
... return bash_completions(prefix, line, begidx, endidx)
31+
...
32+
>>> get_completions('ls /tmp/a*')
33+
({'/tmp/abc '}, 0)
34+
35+
Now, lprefix begins at the first special character:
36+
37+
.. code-block:: sh
38+
39+
$ python
40+
>>> from bash_completion import bash_completions
41+
>>>
42+
>>> def get_completions(line):
43+
... split = line.split()
44+
... if len(split) > 1 and not line.endswith(' '):
45+
... prefix = split[-1]
46+
... begidx = len(line.rsplit(prefix)[0])
47+
... else:
48+
... prefix = ''
49+
... begidx = len(line)
50+
... endidx = len(line)
51+
... return bash_completions(prefix, line, begidx, endidx)
52+
...
53+
>>> get_completions('ls /tmp/a*')
54+
({'/tmp/abc '}, 7)
55+
56+
57+
**Security:** None

0 commit comments

Comments
 (0)