Repository: xonsh/xonsh

Issue:
if _get_bash_completions_source() is None, 'set()' gets into bash completion script
Once again, this is a borderline non-issue.

I'm running NixOS, which does not follow FHS and _get_bash_completions_source() returns `None` there.

While debugging the resulting lack of bash completion, I stumbled upon

https://github.com/xonsh/xonsh/blob/743a8513899cf5a27f0b3aae52e7fec16879f530/xonsh/completers/bash_completion.py#L313

which gets interpolated here

https://github.com/xonsh/xonsh/blob/743a8513899cf5a27f0b3aae52e7fec16879f530/xonsh/completers/bash_completion.py#L313

and sure enough, the bash script now starts with `set()`.

I'm sure that was not @scopatz's original intention.




Discussion:
Thanks for reporting @t184256!  Aren't those the same lines?
Sorry, the second one was meant to be

https://github.com/xonsh/xonsh/blob/743a8513899cf5a27f0b3aae52e7fec16879f530/xonsh/completers/bash_completion.py#L206
Ahh I see.  This should probably raised over at https://github.com/xonsh/py-bash-completion, since xonsh vends this package here.  We can keep this issue open until that is resolved though.

On NixOS, what does `import platform; platform.system()` say? And where do the bash completion scripts live?
> On NixOS, what does import platform; platform.system() say?

`Linux`

> And where do the bash completion scripts live?

The main one that we're trying to source here? It lives inside the `bash-completion` package with an unpredictable path, and the philosophically correct way to point xonsh there should be build-time source patching, a la

```
substituteInPlace xonsh/platform.py --replace \
    '/usr/share/bash-completion/bash_completion' \
    '${pkgs.bash-completion}/etc/profile.d/bash_completion.sh'
```

It's not a bug, it's a feature. Don't lose much sleep over NixOS support, it's something that should be done on their side, not yours.
Actually, a quick question while we're on that topic.

What are the downsides of throwing out all that path guessing logic and replacing line 206 with a simple `PS1=make_bash_think_it_is_interactive source /etc/bashrc`?
Execution time, mainly.  When I was timing it a couple of years ago it was the difference between 10 us and 10 ms, IIRC.  And since this something that gets run when people press TAB, it should be as fast as possible
Reasonable. Then, could we either:

1. Drop a hint in `$BASH_COMPLETIONS` doc that systemwide `bashrc` is fine too?
2. Go ahead and append several guesses to the `bcd`s as a fallback?

Resolving patch:
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
@@ -14,7 +14,7 @@
 import functools
 import subprocess
 
-__version__ = "0.2.2"
+__version__ = "0.2.4"
 
 
 @functools.lru_cache(1)
@@ -310,7 +310,7 @@ def bash_completions(
     lprefix : int
         Length of the prefix to be replaced in the completion.
     """
-    source = _get_bash_completions_source(paths) or set()
+    source = _get_bash_completions_source(paths) or ""
 
     if prefix.startswith("$"):  # do not complete env variables
         return set(), 0


Test patch: