argcomplete 3.7.1__tar.gz → 3.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {argcomplete-3.7.1 → argcomplete-3.8.0}/.github/workflows/ci.yml +1 -1
- argcomplete-3.8.0/AGENTS.md +5 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/Changes.rst +25 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/PKG-INFO +21 -18
- {argcomplete-3.7.1 → argcomplete-3.8.0}/README.rst +18 -14
- {argcomplete-3.7.1 → argcomplete-3.8.0}/argcomplete/__init__.py +5 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/argcomplete/_check_console_script.py +5 -3
- {argcomplete-3.7.1 → argcomplete-3.8.0}/argcomplete/_check_module.py +4 -2
- {argcomplete-3.7.1 → argcomplete-3.8.0}/argcomplete/bash_completion.d/_python-argcomplete +8 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/argcomplete/completers.py +18 -15
- {argcomplete-3.7.1 → argcomplete-3.8.0}/argcomplete/exceptions.py +3 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/argcomplete/finders.py +111 -64
- {argcomplete-3.7.1 → argcomplete-3.8.0}/argcomplete/io.py +2 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/argcomplete/lexers.py +11 -5
- {argcomplete-3.7.1 → argcomplete-3.8.0}/argcomplete/packages/_argparse.py +65 -23
- {argcomplete-3.7.1 → argcomplete-3.8.0}/argcomplete/packages/_shlex.py +10 -6
- {argcomplete-3.7.1 → argcomplete-3.8.0}/argcomplete/scripts/activate_global_python_argcomplete.py +9 -5
- {argcomplete-3.7.1 → argcomplete-3.8.0}/argcomplete/scripts/register_python_argcomplete.py +2 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/argcomplete/shell_integration.py +30 -18
- {argcomplete-3.7.1 → argcomplete-3.8.0}/docs/conf.py +2 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/docs/examples/describe_github_user.py +4 -2
- {argcomplete-3.7.1 → argcomplete-3.8.0}/pyproject.toml +14 -2
- argcomplete-3.8.0/test/powershell_prog.py +16 -0
- argcomplete-3.8.0/test/powershell_quoting.ps1 +50 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/test/prog +3 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/test/test.py +433 -52
- {argcomplete-3.7.1 → argcomplete-3.8.0}/test/test_contrib_shells.py +6 -5
- {argcomplete-3.7.1 → argcomplete-3.8.0}/test/test_package/setup.py +2 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/test/test_package/test_module.py +2 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/test/test_package/test_package/__init__.py +3 -0
- argcomplete-3.8.0/test/test_powershell.py +141 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/.github/FUNDING.yml +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/.github/workflows/release.yml +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/.gitignore +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/Authors.rst +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/LICENSE.rst +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/MANIFEST.in +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/Makefile +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/NOTICE +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/SECURITY.md +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/argcomplete/packages/__init__.py +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/argcomplete/py.typed +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/argcomplete/scripts/__init__.py +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/common.mk +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/contrib/README.rst +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/docs/changelog.rst +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/docs/fish_help_string.png +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/docs/index.rst +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/docs/toc.html +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/setup.cfg +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/test/__init__.py +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/test/inputrc +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/test/stuck +0 -0
- {argcomplete-3.7.1 → argcomplete-3.8.0}/test/test_package/__init__.py +0 -0
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
Changes for v3.8.0 (2026-11-21)
|
|
2
|
+
===============================
|
|
3
|
+
|
|
4
|
+
- Improve tilde-prefixed completions (#579, #581, #587, #588)
|
|
5
|
+
|
|
6
|
+
- Complete only the suffix of a mid-word Bash quote (#589)
|
|
7
|
+
|
|
8
|
+
- Exclude directories from extension-filtered file completions (#582)
|
|
9
|
+
|
|
10
|
+
- Fix completion of attached option values with pending positionals
|
|
11
|
+
(#586)
|
|
12
|
+
|
|
13
|
+
- Avoid IndexError for empty completion suffixes (#576)
|
|
14
|
+
|
|
15
|
+
- Quote PowerShell completions with native escaping (#573)
|
|
16
|
+
|
|
17
|
+
- Expose consumed argument counts to custom completers (#567, #572)
|
|
18
|
+
|
|
19
|
+
- Neutralize IFS byte in zsh completion descriptions (#566)
|
|
20
|
+
|
|
21
|
+
Changes for v3.7.2 (2026-08-05)
|
|
22
|
+
===============================
|
|
23
|
+
|
|
24
|
+
Require Python 3.10+ (#558)
|
|
25
|
+
|
|
1
26
|
Changes for v3.7.1 (2026-08-04)
|
|
2
27
|
===============================
|
|
3
28
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: argcomplete
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.8.0
|
|
4
4
|
Summary: Bash tab completion for argparse
|
|
5
5
|
Project-URL: Homepage, https://github.com/kislyuk/argcomplete
|
|
6
6
|
Project-URL: Documentation, https://kislyuk.github.io/argcomplete
|
|
@@ -22,7 +22,6 @@ Classifier: Operating System :: MacOS :: MacOS X
|
|
|
22
22
|
Classifier: Operating System :: POSIX
|
|
23
23
|
Classifier: Programming Language :: Python
|
|
24
24
|
Classifier: Programming Language :: Python :: 3
|
|
25
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
26
25
|
Classifier: Programming Language :: Python :: 3.10
|
|
27
26
|
Classifier: Programming Language :: Python :: 3.11
|
|
28
27
|
Classifier: Programming Language :: Python :: 3.12
|
|
@@ -34,7 +33,7 @@ Classifier: Topic :: Software Development
|
|
|
34
33
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
35
34
|
Classifier: Topic :: System :: Shells
|
|
36
35
|
Classifier: Topic :: Terminals
|
|
37
|
-
Requires-Python: >=3.
|
|
36
|
+
Requires-Python: >=3.10
|
|
38
37
|
Provides-Extra: test
|
|
39
38
|
Requires-Dist: coverage; extra == 'test'
|
|
40
39
|
Requires-Dist: mypy; extra == 'test'
|
|
@@ -151,6 +150,19 @@ way to do this at definition time is:
|
|
|
151
150
|
parser.add_argument("--env-var2").completer = EnvironCompleter
|
|
152
151
|
argcomplete.autocomplete(parser)
|
|
153
152
|
|
|
153
|
+
For an action that accepts several values, a completer can call
|
|
154
|
+
``argcomplete.get_num_consumed_args(action)`` to distinguish their positions.
|
|
155
|
+
For example, the following completes ``--foobar KEY OP NAME`` differently at
|
|
156
|
+
each position, without changing the callable completer signature:
|
|
157
|
+
|
|
158
|
+
.. code-block:: python
|
|
159
|
+
|
|
160
|
+
def complete_foobar(prefix, action, **kwargs):
|
|
161
|
+
choices = (("owner", "status"), ("eq", "ne"), ("alice", "bob"))
|
|
162
|
+
return choices[argcomplete.get_num_consumed_args(action)]
|
|
163
|
+
|
|
164
|
+
parser.add_argument("--foobar", nargs=3).completer = complete_foobar
|
|
165
|
+
|
|
154
166
|
If you specify the ``choices`` keyword for an argparse option or argument (and don't specify a completer), it will be
|
|
155
167
|
used for completions.
|
|
156
168
|
|
|
@@ -266,8 +278,8 @@ multiple Python versions on the same system, the version being used to run the s
|
|
|
266
278
|
.. admonition:: Bash version compatibility
|
|
267
279
|
|
|
268
280
|
When using bash, global completion requires bash support for ``complete -D``, which was introduced in bash 4.2. Since
|
|
269
|
-
|
|
270
|
-
`Homebrew <http://brew.sh/>`_ (``brew install bash`` - you will also need to add
|
|
281
|
+
macOS ships with an outdated version of Bash (3.2), you can either use zsh or install a newer version of bash using
|
|
282
|
+
`Homebrew <http://brew.sh/>`_ (``brew install bash`` - you will also need to add ``$(brew --prefix)/bin/bash`` to
|
|
271
283
|
``/etc/shells``, and run ``chsh`` to change your shell). You can check the version of the running copy of bash with
|
|
272
284
|
``echo $BASH_VERSION``.
|
|
273
285
|
|
|
@@ -298,11 +310,11 @@ work for zsh as well.
|
|
|
298
310
|
|
|
299
311
|
Python Support
|
|
300
312
|
--------------
|
|
301
|
-
Argcomplete requires Python 3.
|
|
313
|
+
Argcomplete requires Python 3.10+.
|
|
302
314
|
|
|
303
315
|
Support for other shells
|
|
304
316
|
------------------------
|
|
305
|
-
Argcomplete maintainers provide support only for the bash and zsh shells on Linux and
|
|
317
|
+
Argcomplete maintainers provide support only for the bash and zsh shells on Linux and macOS. For resources related to
|
|
306
318
|
other shells and platforms, including fish, tcsh, xonsh, powershell, and Windows, please see the
|
|
307
319
|
`contrib <https://github.com/kislyuk/argcomplete/tree/develop/contrib>`_ directory.
|
|
308
320
|
|
|
@@ -340,15 +352,6 @@ Please report bugs, issues, feature requests, etc. on `GitHub <https://github.co
|
|
|
340
352
|
|
|
341
353
|
License
|
|
342
354
|
-------
|
|
343
|
-
Copyright 2012-
|
|
355
|
+
Copyright 2012-2026, Andrey Kislyuk and argcomplete contributors. Licensed under the terms of the
|
|
344
356
|
`Apache License, Version 2.0 <http://www.apache.org/licenses/LICENSE-2.0>`_. Distribution of the LICENSE and NOTICE
|
|
345
357
|
files with source copies of this package and derivative works is **REQUIRED** as specified by the Apache License.
|
|
346
|
-
|
|
347
|
-
.. image:: https://github.com/kislyuk/argcomplete/workflows/Python%20package/badge.svg
|
|
348
|
-
:target: https://github.com/kislyuk/argcomplete/actions
|
|
349
|
-
.. image:: https://codecov.io/github/kislyuk/argcomplete/coverage.svg?branch=master
|
|
350
|
-
:target: https://codecov.io/github/kislyuk/argcomplete?branch=master
|
|
351
|
-
.. image:: https://img.shields.io/pypi/v/argcomplete.svg
|
|
352
|
-
:target: https://pypi.python.org/pypi/argcomplete
|
|
353
|
-
.. image:: https://img.shields.io/pypi/l/argcomplete.svg
|
|
354
|
-
:target: https://pypi.python.org/pypi/argcomplete
|
|
@@ -106,6 +106,19 @@ way to do this at definition time is:
|
|
|
106
106
|
parser.add_argument("--env-var2").completer = EnvironCompleter
|
|
107
107
|
argcomplete.autocomplete(parser)
|
|
108
108
|
|
|
109
|
+
For an action that accepts several values, a completer can call
|
|
110
|
+
``argcomplete.get_num_consumed_args(action)`` to distinguish their positions.
|
|
111
|
+
For example, the following completes ``--foobar KEY OP NAME`` differently at
|
|
112
|
+
each position, without changing the callable completer signature:
|
|
113
|
+
|
|
114
|
+
.. code-block:: python
|
|
115
|
+
|
|
116
|
+
def complete_foobar(prefix, action, **kwargs):
|
|
117
|
+
choices = (("owner", "status"), ("eq", "ne"), ("alice", "bob"))
|
|
118
|
+
return choices[argcomplete.get_num_consumed_args(action)]
|
|
119
|
+
|
|
120
|
+
parser.add_argument("--foobar", nargs=3).completer = complete_foobar
|
|
121
|
+
|
|
109
122
|
If you specify the ``choices`` keyword for an argparse option or argument (and don't specify a completer), it will be
|
|
110
123
|
used for completions.
|
|
111
124
|
|
|
@@ -221,8 +234,8 @@ multiple Python versions on the same system, the version being used to run the s
|
|
|
221
234
|
.. admonition:: Bash version compatibility
|
|
222
235
|
|
|
223
236
|
When using bash, global completion requires bash support for ``complete -D``, which was introduced in bash 4.2. Since
|
|
224
|
-
|
|
225
|
-
`Homebrew <http://brew.sh/>`_ (``brew install bash`` - you will also need to add
|
|
237
|
+
macOS ships with an outdated version of Bash (3.2), you can either use zsh or install a newer version of bash using
|
|
238
|
+
`Homebrew <http://brew.sh/>`_ (``brew install bash`` - you will also need to add ``$(brew --prefix)/bin/bash`` to
|
|
226
239
|
``/etc/shells``, and run ``chsh`` to change your shell). You can check the version of the running copy of bash with
|
|
227
240
|
``echo $BASH_VERSION``.
|
|
228
241
|
|
|
@@ -253,11 +266,11 @@ work for zsh as well.
|
|
|
253
266
|
|
|
254
267
|
Python Support
|
|
255
268
|
--------------
|
|
256
|
-
Argcomplete requires Python 3.
|
|
269
|
+
Argcomplete requires Python 3.10+.
|
|
257
270
|
|
|
258
271
|
Support for other shells
|
|
259
272
|
------------------------
|
|
260
|
-
Argcomplete maintainers provide support only for the bash and zsh shells on Linux and
|
|
273
|
+
Argcomplete maintainers provide support only for the bash and zsh shells on Linux and macOS. For resources related to
|
|
261
274
|
other shells and platforms, including fish, tcsh, xonsh, powershell, and Windows, please see the
|
|
262
275
|
`contrib <https://github.com/kislyuk/argcomplete/tree/develop/contrib>`_ directory.
|
|
263
276
|
|
|
@@ -295,15 +308,6 @@ Please report bugs, issues, feature requests, etc. on `GitHub <https://github.co
|
|
|
295
308
|
|
|
296
309
|
License
|
|
297
310
|
-------
|
|
298
|
-
Copyright 2012-
|
|
311
|
+
Copyright 2012-2026, Andrey Kislyuk and argcomplete contributors. Licensed under the terms of the
|
|
299
312
|
`Apache License, Version 2.0 <http://www.apache.org/licenses/LICENSE-2.0>`_. Distribution of the LICENSE and NOTICE
|
|
300
313
|
files with source copies of this package and derivative works is **REQUIRED** as specified by the Apache License.
|
|
301
|
-
|
|
302
|
-
.. image:: https://github.com/kislyuk/argcomplete/workflows/Python%20package/badge.svg
|
|
303
|
-
:target: https://github.com/kislyuk/argcomplete/actions
|
|
304
|
-
.. image:: https://codecov.io/github/kislyuk/argcomplete/coverage.svg?branch=master
|
|
305
|
-
:target: https://codecov.io/github/kislyuk/argcomplete?branch=master
|
|
306
|
-
.. image:: https://img.shields.io/pypi/v/argcomplete.svg
|
|
307
|
-
:target: https://pypi.python.org/pypi/argcomplete
|
|
308
|
-
.. image:: https://img.shields.io/pypi/l/argcomplete.svg
|
|
309
|
-
:target: https://pypi.python.org/pypi/argcomplete
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
# Copyright 2012-2023, Andrey Kislyuk and argcomplete contributors.
|
|
2
2
|
# Licensed under the Apache License. See https://github.com/kislyuk/argcomplete for more info.
|
|
3
3
|
|
|
4
|
+
# mypy: implicit-reexport=True
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
4
8
|
from . import completers
|
|
5
9
|
from .completers import ChoicesCompleter, DirectoriesCompleter, EnvironCompleter, FilesCompleter, SuppressCompleter
|
|
6
10
|
from .exceptions import ArgcompleteException
|
|
7
11
|
from .finders import CompletionFinder, ExclusiveCompletionFinder, safe_actions
|
|
8
12
|
from .io import debug, mute_stderr, warn
|
|
9
13
|
from .lexers import split_line
|
|
14
|
+
from .packages._argparse import get_num_consumed_args
|
|
10
15
|
from .shell_integration import shellcode
|
|
11
16
|
|
|
12
17
|
autocomplete: CompletionFinder = CompletionFinder()
|
|
@@ -12,11 +12,13 @@ https://setuptools.readthedocs.io/en/latest/setuptools.html#automatic-script-cre
|
|
|
12
12
|
Intended to be invoked by argcomplete's global completion function.
|
|
13
13
|
"""
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
import os
|
|
16
18
|
import sys
|
|
19
|
+
from collections.abc import Iterable
|
|
17
20
|
from importlib.metadata import EntryPoint
|
|
18
21
|
from importlib.metadata import entry_points as importlib_entry_points
|
|
19
|
-
from typing import Iterable
|
|
20
22
|
|
|
21
23
|
from ._check_module import ArgcompleteMarkerNotFound, find
|
|
22
24
|
|
|
@@ -46,9 +48,9 @@ def main():
|
|
|
46
48
|
# Check this looks like the script we really expected.
|
|
47
49
|
with open(script_path) as f:
|
|
48
50
|
script = f.read()
|
|
49
|
-
if "from {} import {}"
|
|
51
|
+
if f"from {module_name} import {function_name}" not in script:
|
|
50
52
|
raise ArgcompleteMarkerNotFound("does not appear to be a console script")
|
|
51
|
-
if "sys.exit({}())"
|
|
53
|
+
if f"sys.exit({function_name}())" not in script:
|
|
52
54
|
raise ArgcompleteMarkerNotFound("does not appear to be a console script")
|
|
53
55
|
|
|
54
56
|
# Look for the argcomplete marker in the script it imports.
|
|
@@ -7,6 +7,8 @@ The module name should be specified in a form usable with `python -m`.
|
|
|
7
7
|
Intended to be invoked by argcomplete's global completion function.
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
10
12
|
import os
|
|
11
13
|
import sys
|
|
12
14
|
import tokenize
|
|
@@ -26,12 +28,12 @@ def find(name, return_package=False):
|
|
|
26
28
|
break
|
|
27
29
|
|
|
28
30
|
if spec is None:
|
|
29
|
-
raise ArgcompleteMarkerNotFound('no module named "{
|
|
31
|
+
raise ArgcompleteMarkerNotFound(f'no module named "{names[0]}"')
|
|
30
32
|
if not spec.has_location:
|
|
31
33
|
raise ArgcompleteMarkerNotFound("cannot locate file")
|
|
32
34
|
if spec.submodule_search_locations is None:
|
|
33
35
|
if len(names) != 1:
|
|
34
|
-
raise ArgcompleteMarkerNotFound("{} is not a package"
|
|
36
|
+
raise ArgcompleteMarkerNotFound(f"{names[0]} is not a package")
|
|
35
37
|
return spec.origin
|
|
36
38
|
if len(spec.submodule_search_locations) != 1:
|
|
37
39
|
raise ArgcompleteMarkerNotFound("expecting one search location")
|
|
@@ -212,6 +212,14 @@ _python_argcomplete_global() {
|
|
|
212
212
|
_ARGCOMPLETE_SHELL="zsh" \
|
|
213
213
|
_ARGCOMPLETE_SUPPRESS_SPACE=1 \
|
|
214
214
|
__python_argcomplete_run "$executable" "${(@)req_argv[1, ${ARGCOMPLETE}-1]}"))
|
|
215
|
+
# Keep the typed tilde in the word and let _describe quote the rest.
|
|
216
|
+
local tilde_prefix='~'
|
|
217
|
+
[[ $PREFIX != '~'* && $PREFIX == *'=~'* ]] && tilde_prefix="${PREFIX%%=*}=~"
|
|
218
|
+
if [[ -z ${compstate[quote]} && $PREFIX == "$tilde_prefix"* && ${words[CURRENT]} == "$tilde_prefix"* &&
|
|
219
|
+
-z "${completions[@]:#"$tilde_prefix"*}" ]]; then
|
|
220
|
+
compset -p "${#tilde_prefix}"
|
|
221
|
+
completions=("${completions[@]#"$tilde_prefix"}")
|
|
222
|
+
fi
|
|
215
223
|
local nosort=()
|
|
216
224
|
local nospace=()
|
|
217
225
|
if is-at-least 5.8; then
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
# Copyright 2012-2023, Andrey Kislyuk and argcomplete contributors.
|
|
2
2
|
# Licensed under the Apache License. See https://github.com/kislyuk/argcomplete for more info.
|
|
3
3
|
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
4
6
|
import argparse
|
|
5
7
|
import os
|
|
6
8
|
import subprocess
|
|
7
|
-
from collections.abc import Callable, Generator, Iterable
|
|
9
|
+
from collections.abc import Callable, Generator, Iterable
|
|
8
10
|
from shlex import quote
|
|
9
11
|
from typing import Final
|
|
10
12
|
|
|
@@ -32,12 +34,12 @@ class BaseCompleter:
|
|
|
32
34
|
|
|
33
35
|
|
|
34
36
|
class ChoicesCompleter(BaseCompleter):
|
|
35
|
-
choices: Final[
|
|
37
|
+
choices: Final[Iterable[object]]
|
|
36
38
|
|
|
37
|
-
def __init__(self, choices:
|
|
39
|
+
def __init__(self, choices: Iterable[object]) -> None:
|
|
38
40
|
self.choices = choices
|
|
39
41
|
|
|
40
|
-
def _convert(self, choice):
|
|
42
|
+
def _convert(self, choice: object) -> str:
|
|
41
43
|
if not isinstance(choice, str):
|
|
42
44
|
choice = str(choice)
|
|
43
45
|
return choice
|
|
@@ -74,21 +76,20 @@ class FilesCompleter(BaseCompleter):
|
|
|
74
76
|
# correctly in older versions and calling bind makes them available. For details, see
|
|
75
77
|
# https://savannah.gnu.org/support/index.php?111125
|
|
76
78
|
files = _call(
|
|
77
|
-
["bash", "-c", "bind; compgen -A directory -- {
|
|
79
|
+
["bash", "-c", f"bind; compgen -A directory -- {quote(prefix)}"],
|
|
78
80
|
stderr=subprocess.DEVNULL,
|
|
79
81
|
)
|
|
80
82
|
completion += [f + "/" for f in files]
|
|
81
83
|
for x in self.allowednames:
|
|
82
|
-
|
|
83
|
-
["bash", "-c", "bind; compgen -A file -X '!*.{
|
|
84
|
+
files = _call(
|
|
85
|
+
["bash", "-c", f"bind; compgen -A file -X '!*.{x}' -- {quote(prefix)}"],
|
|
84
86
|
stderr=subprocess.DEVNULL,
|
|
85
87
|
)
|
|
88
|
+
completion += [f for f in files if not os.path.isdir(os.path.expanduser(f))]
|
|
86
89
|
else:
|
|
87
|
-
completion += _call(
|
|
88
|
-
["bash", "-c", "bind; compgen -A file -- {p}".format(p=quote(prefix))], stderr=subprocess.DEVNULL
|
|
89
|
-
)
|
|
90
|
+
completion += _call(["bash", "-c", f"bind; compgen -A file -- {quote(prefix)}"], stderr=subprocess.DEVNULL)
|
|
90
91
|
anticomp = _call(
|
|
91
|
-
["bash", "-c", "bind; compgen -A directory -- {
|
|
92
|
+
["bash", "-c", f"bind; compgen -A directory -- {quote(prefix)}"],
|
|
92
93
|
stderr=subprocess.DEVNULL,
|
|
93
94
|
)
|
|
94
95
|
completion = list(set(completion) - set(anticomp))
|
|
@@ -115,15 +116,16 @@ class _FilteredFilesCompleter(BaseCompleter):
|
|
|
115
116
|
"""
|
|
116
117
|
Provide completions on prefix
|
|
117
118
|
"""
|
|
119
|
+
prefix_dir = os.path.dirname(prefix)
|
|
118
120
|
# Expand a leading "~" so that filesystem operations below work on a
|
|
119
121
|
# real path (os.listdir("~") would otherwise raise FileNotFoundError).
|
|
120
|
-
|
|
121
|
-
target_dir = os.path.
|
|
122
|
+
# The completions keep the directory as typed, so that they still start with the prefix.
|
|
123
|
+
target_dir = os.path.expanduser(prefix_dir)
|
|
122
124
|
try:
|
|
123
125
|
names = os.listdir(target_dir or ".")
|
|
124
126
|
except Exception:
|
|
125
127
|
return # empty iterator
|
|
126
|
-
incomplete_part = os.path.basename(
|
|
128
|
+
incomplete_part = os.path.basename(prefix)
|
|
127
129
|
# Iterate on target_dir entries and filter on given predicate
|
|
128
130
|
for name in names:
|
|
129
131
|
if not name.startswith(incomplete_part):
|
|
@@ -131,7 +133,8 @@ class _FilteredFilesCompleter(BaseCompleter):
|
|
|
131
133
|
candidate = os.path.join(target_dir, name)
|
|
132
134
|
if not self.predicate(candidate):
|
|
133
135
|
continue
|
|
134
|
-
|
|
136
|
+
completion = os.path.join(prefix_dir, name)
|
|
137
|
+
yield completion + "/" if os.path.isdir(candidate) else completion
|
|
135
138
|
|
|
136
139
|
|
|
137
140
|
class DirectoriesCompleter(_FilteredFilesCompleter):
|