# Buggy code
def windows_bash_command():
    """Determines the command for Bash on windows."""
    # Check that bash is on path otherwise try the default directory
    # used by Git for windows
    wbc = "bash"
    cmd_cache = builtins.__xonsh_commands_cache__
    bash_on_path = cmd_cache.lazy_locate_binary("bash", ignore_alias=True)
    if bash_on_path:
        try:
            out = subprocess.check_output(
                [bash_on_path, "--version"],
                stderr=subprocess.PIPE,
                universal_newlines=True,
            )
        except subprocess.CalledProcessError:
            bash_works = False
        else:
            # Check if Bash is from the "Windows Subsystem for Linux" (WSL)
            # which can't be used by xonsh foreign-shell/completer
            bash_works = "pc-linux-gnu" not in out.splitlines()[0]

        if bash_works:
            wbc = bash_on_path
        else:
            gfwp = git_for_windows_path()
            if gfwp:
                bashcmd = os.path.join(gfwp, "bin\\bash.exe")
                if os.path.isfile(bashcmd):
                    wbc = bashcmd
    return wbc


# Traceback (IndexError)
$ python Exception in thread Thread-81:
Traceback (most recent call last):
File "C:\Python35-32\lib\threading.py", line 914, in _bootstrap_inner
self.run()
File "C:\Python35-32\lib\threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "C:\Python35-32\lib\site-packages\prompt_toolkit\interface.py", line 835, in run
completions = list(buffer.completer.get_completions(document, complete_event))
File "C:\Python35-32\lib\site-packages\xonsh\ptk\completer.py", line 49, in get_completions
self.ctx)
File "C:\Python35-32\lib\site-packages\xonsh\__amalgam__.py", line 124, in complete
out = func(prefix, line, begidx, endidx, ctx)
File "C:\Python35-32\lib\site-packages\xonsh\completers\__amalgam__.py", line 1442, in complete_from_bash
command = xp.bash_command()
File "C:\Python35-32\lib\site-packages\xonsh\__amalgam__.py", line 1664, in bash_command
bc = windows_bash_command()
File "C:\Python35-32\lib\site-packages\xonsh\__amalgam__.py", line 1629, in windows_bash_command
bash_works = 'pc-linux-gnu' not in out.splitlines()[0]
IndexError: list index out of range

# Fixed code
def windows_bash_command():
    """Determines the command for Bash on windows."""
    # Check that bash is on path otherwise try the default directory
    # used by Git for windows
    wbc = "bash"
    cmd_cache = builtins.__xonsh_commands_cache__
    bash_on_path = cmd_cache.lazy_locate_binary("bash", ignore_alias=True)
    if bash_on_path:
        try:
            out = subprocess.check_output(
                [bash_on_path, "--version"],
                stderr=subprocess.PIPE,
                universal_newlines=True,
            )
        except subprocess.CalledProcessError:
            bash_works = False
        else:
            # Check if Bash is from the "Windows Subsystem for Linux" (WSL)
            # which can't be used by xonsh foreign-shell/completer
            bash_works = out and "pc-linux-gnu" not in out.splitlines()[0]

        if bash_works:
            wbc = bash_on_path
        else:
            gfwp = git_for_windows_path()
            if gfwp:
                bashcmd = os.path.join(gfwp, "bin\\bash.exe")
                if os.path.isfile(bashcmd):
                    wbc = bashcmd
    return wbc