Repository: xonsh/xonsh

Issue:
Trailing space incorrectly appended when tab-completing command arguments that use equals sign
Related to #4746

When completing commands like `dd status=progress`, when I type `dd sta` and hit `TAB`, I get `dd status= ` (with a trailing space). 

There should not be that trailing space because the `dd` command accepts `status=<something>` as a single argument that does not contain spaces.

<!--- Provide a general summary of the issue in the Title above -->
<!--- If you have a question along the lines of "How do I do this Bash command in xonsh"
please first look over the Bash to Xonsh translation guide: https://xon.sh/bash_to_xsh.html
If you don't find an answer there, please do open an issue! -->

## xonfig

<details>

```
+------------------+-------------------------+
| xonsh            | 0.11.0                  |
| Git SHA          | 18d655e1                |
| Commit Date      | Apr 10 04:16:56 2022    |
| Python           | 3.9.10                  |
| PLY              | 3.11                    |
| have readline    | True                    |
| prompt toolkit   | 3.0.28                  |
| shell type       | prompt_toolkit          |
| history backend  | sqlite                  |
| pygments         | 2.9.0                   |
| on posix         | True                    |
| on linux         | True                    |
| distro           | fedora                  |
| on wsl           | False                   |
| on darwin        | False                   |
| on windows       | False                   |
| on cygwin        | False                   |
| on msys2         | False                   |
| is superuser     | False                   |
| default encoding | utf-8                   |
| xonsh encoding   | utf-8                   |
| encoding errors  | surrogateescape         |
| xontrib          | []                      |
| RC file 1        | /home/yaxollum/.xonshrc |
+------------------+-------------------------+
```

</details>

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**



Discussion:

Resolving patch:
diff --git a/xonsh/completers/bash.py b/xonsh/completers/bash.py
--- a/xonsh/completers/bash.py
+++ b/xonsh/completers/bash.py
@@ -4,7 +4,6 @@
 import xonsh.tools as xt
 from xonsh.built_ins import XSH
 from xonsh.completers.bash_completion import bash_completions
-from xonsh.completers.path import _quote_paths
 from xonsh.completers.tools import RichCompletion, contextual_command_completer
 from xonsh.parsers.completion_context import CommandContext
 
@@ -41,7 +40,6 @@ def complete_from_bash(context: CommandContext):
         env=env,
         paths=paths,
         command=command,
-        quote_paths=_quote_paths,
         line_args=args,
         opening_quote=opening_quote,
         closing_quote=closing_quote,
diff --git a/xonsh/completers/bash_completion.py b/xonsh/completers/bash_completion.py
--- a/xonsh/completers/bash_completion.py
+++ b/xonsh/completers/bash_completion.py
@@ -186,7 +186,7 @@ def _bash_quote_paths(paths, start, end):
             start = end = _bash_quote_to_use(s)
         if os.path.isdir(_bash_expand_path(s)):
             _tail = slash
-        elif end == "":
+        elif end == "" and not s.endswith("="):
             _tail = space
         else:
             _tail = ""


Test patch:
diff --git a/tests/completers/test_bash_completer.py b/tests/completers/test_bash_completer.py
--- a/tests/completers/test_bash_completer.py
+++ b/tests/completers/test_bash_completer.py
@@ -179,3 +179,33 @@ def test_bash_completer_empty_prefix():
     )
     bash_completions, bash_lprefix = complete_from_bash(context)
     assert {"clean", "show"}.issubset(bash_completions)
+
+
+@skip_if_on_darwin
+@skip_if_on_windows
+@pytest.mark.parametrize(
+    "command_context, completions, lprefix",
+    (
+        # dd sta  ->  dd status=
+        (
+            CommandContext(args=(CommandArg("dd"),), arg_index=1, prefix="sta"),
+            {"status="},
+            3,
+        ),
+        # date --da  ->  date --date=
+        (
+            CommandContext(args=(CommandArg("date"),), arg_index=1, prefix="--da"),
+            {"--date="},
+            4,
+        ),
+    ),
+)
+def test_equal_sign_arg(command_context, completions, lprefix):
+    bash_completions, bash_lprefix = complete_from_bash(
+        CompletionContext(command_context)
+    )
+    assert bash_completions == completions and bash_lprefix == lprefix
+    assert all(
+        isinstance(comp, RichCompletion) and not comp.append_space
+        for comp in bash_completions
+    )  # there should not be an appended space after the equal sign
diff --git a/tests/test_path_completers.py b/tests/completers/test_path_completers.py
similarity index 81%
rename from tests/test_path_completers.py
rename to tests/completers/test_path_completers.py
--- a/tests/test_path_completers.py
+++ b/tests/completers/test_path_completers.py
@@ -63,6 +63,24 @@ def test_complete_path_when_prefix_is_raw_path_string(
         assert expected == out[0].pop()
 
 
+def test_complete_path_ending_with_equal_sign(xession, completion_context_parse):
+    xession.env = {
+        "CASE_SENSITIVE_COMPLETIONS": True,
+        "GLOB_SORTED": True,
+        "SUBSEQUENCE_PATH_COMPLETION": False,
+        "FUZZY_PATH_COMPLETION": False,
+        "SUGGEST_THRESHOLD": 1,
+        "CDPATH": set(),
+    }
+    with tempfile.NamedTemporaryFile(suffix="=") as tmp:
+        prefix_file_name = tmp.name.replace("=", "")
+        prefix = prefix_file_name
+        line = f"ls {prefix}"
+        out = xcp.complete_path(completion_context_parse(line, len(line)))
+        expected = f"{tmp.name} "  # has trailing space
+        assert expected == out[0].pop()
+
+
 @pytest.mark.parametrize("prefix", ("", "r", "p", "pr", "rp"))
 def test_path_from_partial_string(prefix):
     string = "hello"