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

Commit 2eaa9e2

Browse files
Enable passing the line arguments (#19)
* Enable passing the line arguments * Allow passing arguments for `quote_paths` * Update bash_completion.py --------- Co-authored-by: Andy Kipp <anki-code@users.noreply.github.com>
1 parent 8acdbd8 commit 2eaa9e2

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

bash_completion.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ def bash_completions(
288288
paths=None,
289289
command=None,
290290
quote_paths=_bash_quote_paths,
291+
line_args=None,
292+
opening_quote="",
293+
closing_quote="",
291294
arg_index=None,
292295
**kwargs
293296
):
@@ -321,9 +324,16 @@ def bash_completions(
321324
this as the default is acceptable 99+% of the time. This function should
322325
return a set of the new paths and a boolean for whether the paths were
323326
quoted.
327+
line_args : list of str, optional
328+
A list of the args in the current line to be used instead of ``line.split()``.
329+
This is usefull with a space in an argument, e.g. ``ls 'a dir/'<TAB>``.
330+
opening_quote : str, optional
331+
The current argument's opening quote. This is passed to the `quote_paths` function.
332+
closing_quote : str, optional
333+
The closing quote that **should** be used. This is also passed to the `quote_paths` function.
324334
arg_index : int, optional
325335
The current prefix's index in the args.
326-
336+
327337
Returns
328338
-------
329339
rtn : set of str
@@ -336,7 +346,7 @@ def bash_completions(
336346
if prefix.startswith("$"): # do not complete env variables
337347
return set(), 0
338348

339-
splt = line.split()
349+
splt = line_args or line.split()
340350
cmd = splt[0]
341351
cmd = os.path.basename(cmd)
342352
prev = ""
@@ -404,7 +414,7 @@ def bash_completions(
404414
strip_len += 1
405415

406416
if "-o noquote" not in complete_stmt:
407-
out, need_quotes = quote_paths(out, "", "")
417+
out, need_quotes = quote_paths(out, opening_quote, closing_quote)
408418
if "-o nospace" in complete_stmt:
409419
out = set([x.rstrip() for x in out])
410420

0 commit comments

Comments
 (0)