internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: xonsh/xonsh

Issue:
xonsh doesn't play well with percol
<!--- 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>

```
$ xonfig
+------------------+-----------------+
| xonsh            | 0.9.8           |
| Python           | 3.7.4           |
| PLY              | 3.11            |
| have readline    | True            |
| prompt toolkit   | None            |
| shell type       | readline        |
| pygments         | 2.3.1           |
| on posix         | True            |
| on linux         | True            |
| distro           | unknown         |
| 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 |
+------------------+-----------------+
```

</details>

## Expected Behavior
<!--- Tell us what should happen -->
`ps aux | percol` works fine in bash/fish/zsh, but not in xonsh. 
![image](https://user-images.githubusercontent.com/37442588/65205541-2e7c8800-dac0-11e9-91f4-1bdc0de404e6.png)

## Current Behavior
![image](https://user-images.githubusercontent.com/37442588/65205710-553abe80-dac0-11e9-92f3-d75c998b3e4b.png)


## Steps to Reproduce
<!--- Please try to write out a minimal reproducible snippet to trigger the bug, it will help us fix it! -->

sudo apt install percol
ps aux | percol


Discussion:
Thanks for reporting @FirstLoveLife !  For a temporary workaround, you can add the following to your `xonshrc` and things should work as expected:

```
__xonsh__.commands_cache.threadable_predictors['percol'] = lambda x: False
```

Looks like our heuristics for detecting curses-like things aren't catching `percol` for some reason.
Probably because it is written in Python and doesn't have the curses link soon enough.  Let's add this to the stock ones

Resolving patch:
diff --git a/xonsh/commands_cache.py b/xonsh/commands_cache.py
--- a/xonsh/commands_cache.py
+++ b/xonsh/commands_cache.py
@@ -474,6 +474,7 @@ def default_threadable_predictors():
         "nano": predict_help_ver,
         "nmcli": predict_true,
         "nvim": predict_false,
+        "percol": predict_false,
         "ponysay": predict_help_ver,
         "psql": predict_false,
         "push": predict_shell,


Test patch:
Repository: xonsh/xonsh

Issue:
The online xonsh (via repl.it) is broken
When I go to [https://xon.sh/](https://xon.sh/) the prompt under **Try it now!** shows me only a plain Python prompt, not a xonsh prompt.

Even `import xonsh` gives a `ModuleNotFoundError`. So it looks like repl.it's Python REPL does not install the packages from the `requirements.txt`.


Discussion:
Yep, I have been working on a replacement for this

Resolving patch:
diff --git a/docs/conf.py b/docs/conf.py
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -67,6 +67,7 @@ def setup(sphinx):
     #'sphinx.ext.autosummary',
     "numpydoc",
     "cmdhelp",
+    "runthis.sphinxext",
 ]
 
 # Add any paths that contain templates here, relative to this directory.
@@ -277,6 +278,8 @@ def setup(sphinx):
 # Prevent numpy from making silly tables
 numpydoc_show_class_members = False
 
+# runthis
+runthis_server = "https://runthis.xonsh.org:80"
 
 #
 # Auto-generate some docs


Test patch:
Repository: xonsh/xonsh

Issue:
xdg-open doesn't go to background by itself
## Current Behavior
When using `xdg-open doc.pdf`, okular (my default pdf reader) opens as expected. Terminal is blocked until okular is closed. Unless ` &` is used explicitly, of course.

## Expected Behavior
In bash, `xdg-open doc.pdf` *automatically* goes to the background after starting, even without using `&` explicitly. This is the behaviour I'm used to and expected. xdg-open is not aliased or anything in bash.

## Workaround
So I have `aliases["o"]="xdg-open"` normally, and this can be replaced by a function that calls xdg-open with `&` such that it is sent to background as expected. 

I filed this issue anyway because I don't really know why bash and xonsh differ in how they treat xdg-open (as I believe in both cases it resolves directly to the shell script `/usr/bin/xdg-open`), so I thought it could be a bug. 

## xonfig

```
$ xonfig
+------------------+----------------------+
| xonsh            | 0.9.13.dev1          |
| Git SHA          | 9f7ccc65             |
| Commit Date      | Oct 15 17:14:50 2019 |
| Python           | 3.7.6                |
| PLY              | 3.11                 |
| have readline    | True                 |
| prompt toolkit   | 2.0.9                |
| shell type       | prompt_toolkit2      |
| pygments         | 2.4.2                |
| on posix         | True                 |
| on linux         | True                 |
| distro           | fedora               |
| 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      |
+------------------+----------------------+
```




Discussion:
Hi @jonaslb, `xdg-open` is a simple script, that behaves very much in dependence on the desktop environment you run. I use Plasma DE and, yes, I can reproduce the issue. Under both Xonsh and Bash the `xdg-open` invocation ultimately ends in a call to `kde-open5`. So it really is `kde-open5` that behaves differently depending on the shell it was started from. I can check its source code to see what the difference is, but I can't (and don't want to either) fix other DEs.
Turns out that `kde-open` decides according to the identity of `stdin`, `stdout` descriptors. Try to add `__xonsh__.commands_cache.threadable_predictors['xdg-open'] = lambda args: False` to your `.xonshrc`.
This is maybe one of the things that should by default be turned off.  PRs welcome!
Sure, PR incoming.

Resolving patch:
diff --git a/xonsh/commands_cache.py b/xonsh/commands_cache.py
--- a/xonsh/commands_cache.py
+++ b/xonsh/commands_cache.py
@@ -510,6 +510,7 @@ def default_threadable_predictors():
         "weechat": predict_help_ver,
         "wget": predict_true,
         "xclip": predict_help_ver,
+        "xdg-open": predict_false,
         "xo": predict_help_ver,
         "xon.sh": predict_shell,
         "xonsh": predict_shell,


Test patch:
Repository: xonsh/xonsh

Issue:
Fuzzy autocomplete is not working with relative path
Hi! The xonsh is great!

I have the case:
```
mkdir -p /tmp/test/dir1 /tmp/test/dir2

cd /tmp/test
ls 2<tab>        # autocomplete shows dir2
ls ./2<tab>      # autocomplete shows nothing, "dir2" expected

cd /tmp/test/dir1
ls ../2<tab>     # autocomplete shows nothing, "dir2" expected
```
It looks like if there is `.` in the path it is not working.

What I'm doing wrong?

<details>

```
$ xonfig                                                                                                                                                                                                                               
+------------------+----------------------+
| xonsh            | 0.9.17               |
| Git SHA          | feeb6315             |
| Commit Date      | Mar 19 10:50:33 2020 |
| Python           | 3.7.6                |
| PLY              | 3.11                 |
| have readline    | True                 |
| prompt toolkit   | 3.0.3                |
| shell type       | prompt_toolkit2      |
| pygments         | 2.5.2                |
| on posix         | True                 |
| on linux         | True                 |
| distro           | unknown              |
| 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      |
+------------------+----------------------+
```

</details>



Discussion:
Thanks for posting this @anki-code! I am seeing this same issue.  It must not be normalizing the paths. Any help here would be really appreciated!

Resolving patch:
diff --git a/xonsh/completers/path.py b/xonsh/completers/path.py
--- a/xonsh/completers/path.py
+++ b/xonsh/completers/path.py
@@ -299,9 +299,13 @@ def complete_path(prefix, line, start, end, ctx, cdpath=True, filtfunc=None):
         # see above functions for details.
         p = _splitpath(os.path.expanduser(prefix))
         if len(p) != 0:
-            if p[0] == "":
-                basedir = ("",)
-                p = p[1:]
+            relative_char = ["", ".", ".."]
+            if p[0] in relative_char:
+                i = 0
+                while p[i] in relative_char:
+                    i += 1
+                basedir = p[:i]
+                p = p[i:]
             else:
                 basedir = None
             matches_so_far = {basedir}


Test patch:
Repository: xonsh/xonsh

Issue:
Include signature of functions in help (? in Python mode)
In xonsh:
```
$ from pathlib import Path                                         
$ p = Path.cwd()                                                   
$ p.mkdir?                                                         
Type:         method
String form:  <bound method Path.mkdir of PosixPath('/home/pierre')>
File:         /usr/lib/python3.8/pathlib.py
Docstring:    Create a new directory at this given path.


<bound method Path.mkdir of PosixPath('/home/pierre')>
```

I tend to think the IPython output is better, in particular because it includes the signature:
```
$ ipython                                                          
Python 3.8.2 (default, Apr 29 2020, 17:54:06) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.13.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from pathlib import Path                                                

In [2]: p = Path.cwd()                                                          

In [3]: p.mkdir?                                                                
Signature: p.mkdir(mode=511, parents=False, exist_ok=False)
Docstring: Create a new directory at this given path.
File:      ~/.pyenv/versions/3.8.2/lib/python3.8/pathlib.py
Type:      method
```

Could the signature be also included in xonsh?



Discussion:

Resolving patch:
diff --git a/xonsh/inspectors.py b/xonsh/inspectors.py
--- a/xonsh/inspectors.py
+++ b/xonsh/inspectors.py
@@ -356,7 +356,7 @@ def _getdef(self, obj, oname=""):
         exception is suppressed.
         """
         try:
-            hdef = oname + inspect.signature(*getargspec(obj))
+            hdef = oname + str(inspect.signature(obj))
             return cast_unicode(hdef)
         except:  # pylint:disable=bare-except
             return None


Test patch:
Repository: xonsh/xonsh

Issue:
Callable alias hung if returning list.
<!--- 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>

```
ftian@ftian-desktop:~$ xonsh
ftian@ftian-desktop ~ $ def _foo(args): 
.......................     return [1, 2], [3, 4] 
.......................                                                                         
ftian@ftian-desktop ~ $ aliases['foo'] = _foo                                                   
ftian@ftian-desktop ~ $ foo                                                                     
Exception in thread Thread-138:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.8/dist-packages/xonsh/__amalgam__.py", line 15040, in run
    self.returncode = parse_proxy_return(r, sp_stdout, sp_stderr)
  File "/usr/local/lib/python3.8/dist-packages/xonsh/__amalgam__.py", line 14785, in parse_proxy_return
    stdout.write(r[0])
TypeError: write() argument must be str, not list



```

</details>

## Expected Behavior
<!--- Tell us what should happen -->
Error.

## Current Behavior
<!--- Tell us what happens instead of the expected behavior -->
xonsh hung, ^C won't kill it either.

<!--- If part of your bug report is a traceback, please first enter debug mode before triggering the error
To enter debug mode, set the environment variable `XONSH_DEBUG=1` _before_ starting `xonsh`.
On Linux and OSX, an easy way to to do this is to run `env XONSH_DEBUG=1 xonsh` -->

### Traceback (if applicable)

<details>

```
traceback
```

</details>

## Steps to Reproduce
<!--- Please try to write out a minimal reproducible snippet to trigger the bug, it will help us fix it! -->



Discussion:
Hi @fengttt, thanks for reporting and sorry for the delay.
I can confirm the issue.

Resolving patch:
diff --git a/xonsh/proc.py b/xonsh/proc.py
--- a/xonsh/proc.py
+++ b/xonsh/proc.py
@@ -1203,12 +1203,12 @@ def parse_proxy_return(r, stdout, stderr):
     elif isinstance(r, cabc.Sequence):
         rlen = len(r)
         if rlen > 0 and r[0] is not None:
-            stdout.write(r[0])
+            stdout.write(str(r[0]))
             stdout.flush()
         if rlen > 1 and r[1] is not None:
-            stderr.write(r[1])
+            stderr.write(str(r[1]))
             stderr.flush()
-        if rlen > 2 and r[2] is not None:
+        if rlen > 2 and isinstance(r[2], int):
             cmd_result = r[2]
     elif r is not None:
         # for the random object...


Test patch:
Repository: xonsh/xonsh

Issue:
Feature request: exit 1 should work
Currently the commands "exit 0" or "exit 1" don't do anything.
It would be nice if it would do the same as "sys.exit(0/1)" to make it easier and faster to convert a bash script to xonsh.


Discussion:

Resolving patch:
diff --git a/xonsh/main.py b/xonsh/main.py
--- a/xonsh/main.py
+++ b/xonsh/main.py
@@ -441,10 +441,17 @@ def func_sig_ttin_ttou(n, f):
     shell = builtins.__xonsh__.shell
     history = builtins.__xonsh__.history
     exit_code = 0
+
+    if shell and not env["XONSH_INTERACTIVE"]:
+        shell.ctx.update({"exit": sys.exit})
+
     try:
         if args.mode == XonshMode.interactive:
             # enter the shell
+
+            # Setted again here because it is possible to call main_xonsh() without calling premain(), namely in the tests.
             env["XONSH_INTERACTIVE"] = True
+
             ignore_sigtstp()
             if env["XONSH_INTERACTIVE"] and not any(
                 os.path.isfile(i) for i in env["XONSHRC"]


Test patch:
Repository: xonsh/xonsh

Issue:
PTK completion prefix matching is broken
I believe #3774 had a few unintended side-effects (and also laid out that we probably need more completion tests).


## xonfig

<details>

```
$ xonfig
+------------------+----------------------+
| xonsh            | 0.9.22.dev165        |
| Git SHA          | 580b675f             |
| Commit Date      | Sep 30 19:48:13 2020 |
| Python           | 3.8.5                |
| PLY              | 3.11                 |
| have readline    | True                 |
| prompt toolkit   | 3.0.7                |
| shell type       | prompt_toolkit       |
| pygments         | 2.6.1                |
| on posix         | True                 |
| on linux         | False                |
| on darwin        | True                 |
| on windows       | False                |
| on cygwin        | False                |
| on msys2         | False                |
| is superuser     | False                |
| default encoding | utf-8                |
| xonsh encoding   | utf-8                |
| encoding errors  | surrogateescape      |
| on jupyter       | False                |
| jupyter kernel   | None                 |
+------------------+----------------------+
```

</details>

## Expected Behavior
When completing available options, we should insert the entirety of the matching prefix of all available options, nothing more.

E.g. if I have this folder structure:

```
dask/
  dask/
  distributed/
```

and I type

```
cd dask/<TAB>
```

it should fill in the common `d` and then stop.

## Current Behavior

In the above, when I type `cd dask/<TAB>` it autoselects `dask/dask`

## Steps to Reproduce

```
mkdir -p dask/dask dask/distributed
cd dask/<TAB>
```

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**



Discussion:
Potential fix in  #3835

Resolving patch:
diff --git a/xonsh/ptk_shell/key_bindings.py b/xonsh/ptk_shell/key_bindings.py
--- a/xonsh/ptk_shell/key_bindings.py
+++ b/xonsh/ptk_shell/key_bindings.py
@@ -206,15 +206,6 @@ def insert_indent(event):
         env = builtins.__xonsh__.env
         event.cli.current_buffer.insert_text(env.get("INDENT"))
 
-    @handle(Keys.Tab, filter=~tab_insert_indent)
-    def start_complete(event):
-        """If starting completions, automatically move to first option"""
-        buff = event.app.current_buffer
-        if buff.complete_state:
-            buff.complete_next()
-        else:
-            buff.start_completion(select_first=True)
-
     @handle(Keys.ControlX, Keys.ControlE, filter=~has_selection)
     def open_editor(event):
         """ Open current buffer in editor """


Test patch:
Repository: xonsh/xonsh

Issue:
CommandsCache: reading the directory from PATH and the symlink to this directory from PATH (double work)
This is the second part of #3912

While I worked on #3911 I found that reading of the files in the PATH directories was done many times. 

I found that there is reading the directory from PATH and reading the symlink to this directory from PATH again. It makes xonsh start on Linux slower.

For example details by directories on Ubuntu:
```python
all=0
for p in $PATH:
    print(p)
    a=len([l for l in fp'{p}'.glob('*')])
    all += a
    print(a)
print('Total', all)
```
```bash
/opt/miniconda/bin
353
/opt/miniconda/condabin
1
/home/pc/.local/bin
2
/usr/local/sbin
0
/usr/local/bin
0
/usr/sbin
420
/usr/bin
2298
/sbin
420
/bin
2298
/usr/games
0
/usr/local/games
0
/snap/bin
3

Total 5795
```
And we can see that:
```bash
ls -la /bin
#/bin -> usr/bin

ls -la /sbin
#/sbin -> /usr/sbin
```
So xonsh scan the same directory twice.

As result instead of scan 5795-2298-420=3077 files once it scans 5795 files 3 times = 17,385 in sum.

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**



Discussion:

Resolving patch:
diff --git a/xonsh/commands_cache.py b/xonsh/commands_cache.py
--- a/xonsh/commands_cache.py
+++ b/xonsh/commands_cache.py
@@ -70,7 +70,7 @@ def get_possible_names(name):
     @staticmethod
     def remove_dups(p):
         ret = list()
-        for e in p:
+        for e in map(os.path.realpath, p):
             if e not in ret:
                 ret.append(e)
         return ret


Test patch:
diff --git a/tests/test_environ.py b/tests/test_environ.py
--- a/tests/test_environ.py
+++ b/tests/test_environ.py
@@ -150,6 +150,7 @@ def test_swap_exception_replacement():
 def test_locate_binary_on_windows(xonsh_builtins):
     files = ("file1.exe", "FILE2.BAT", "file3.txt")
     with TemporaryDirectory() as tmpdir:
+        tmpdir = os.path.realpath(tmpdir)
         for fname in files:
             fpath = os.path.join(tmpdir, fname)
             with open(fpath, "w") as f:
Repository: xonsh/xonsh

Issue:
print_color raises exception from RC file
Hi! Xonsh is super incredible! Thanks!

I've found that `print_color` not working when it used in rc-file:
```bash
# bash
cd /tmp
echo 'from xonsh.tools import print_color' > rc
echo 'print_color("{RED}Hello!")' >> rc
XONSH_DEBUG=1 XONSH_SHOW_TRACEBACK=1 xonsh --rc rc
```
Result:
```
Traceback (most recent call last):
  File "/opt/miniconda/lib/python3.8/site-packages/xonsh/environ.py", line 2245, in xonsh_script_run_control
    run_script_with_cache(filename, execer, ctx)
  File "/opt/miniconda/lib/python3.8/site-packages/xonsh/codecache.py", line 162, in run_script_with_cache
    run_compiled_code(ccode, glb, loc, mode)
  File "/opt/miniconda/lib/python3.8/site-packages/xonsh/codecache.py", line 67, in run_compiled_code
    func(code, glb, loc)
  File "rc", line 3, in <module>
    print_color('{RED}123')
  File "/opt/miniconda/lib/python3.8/site-packages/xonsh/tools.py", line 1783, in print_color
    builtins.__xonsh__.shell.shell.print_color(string, **kwargs)
AttributeError: 'NoneType' object has no attribute 'shell'
```

For example `aliases.py` contain `print_color` and could fail from rc.

It's on current master - `580b675f` (Oct 1 02:48:13 2020).

Please fix. Thanks!

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**



Discussion:

Resolving patch:
diff --git a/xonsh/tools.py b/xonsh/tools.py
--- a/xonsh/tools.py
+++ b/xonsh/tools.py
@@ -1837,7 +1837,14 @@ def format_color(string, **kwargs):
     shell instances method of the same name. The results of this function should
     be directly usable by print_color().
     """
-    return builtins.__xonsh__.shell.shell.format_color(string, **kwargs)
+    if hasattr(builtins.__xonsh__.shell, "shell"):
+        return builtins.__xonsh__.shell.shell.format_color(string, **kwargs)
+    else:
+        # fallback for ANSI if shell is not yet initialized
+        from xonsh.ansi_colors import ansi_partial_color_format
+
+        style = builtins.__xonsh__.env.get("XONSH_COLOR_STYLE")
+        return ansi_partial_color_format(string, style=style)
 
 
 def print_color(string, **kwargs):
@@ -1845,7 +1852,11 @@ def print_color(string, **kwargs):
     method of the same name. Colors will be formatted if they have not already
     been.
     """
-    builtins.__xonsh__.shell.shell.print_color(string, **kwargs)
+    if hasattr(builtins.__xonsh__.shell, "shell"):
+        builtins.__xonsh__.shell.shell.print_color(string, **kwargs)
+    else:
+        # fallback for ANSI if shell is not yet initialized
+        print(format_color(string, **kwargs))
 
 
 def color_style_names():


Test patch: