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

Issue:
`which` takes not `-v` on OS X
Only, `-a` or `s`.  Though `which_version` (the `xonsh/alias.py` function) does invoke `which` with `-v`

This is untrue if you `brew install gnu-which --with-default-names`, which I guess not many people do... and we **could** determine that by looking as wether the `gnu`string is in the output of `which` without any arguments...

Woosh, with wish which was not [a witch](https://www.youtube.com/watch?v=zrzMhU_4m-g).



Discussion:
Hey @Carreau -- who are you that is so wise in the ways of science?

Which command line flag should be passed to `gnu-which` to trigger the version info?  I was browsing through the source and it looks like it _should_ accept `-v` or `-V` but I gather it doesn't?

> Hey @Carreau -- who are you that is so wise in the ways of science?

A duck, I'm typing, so it's duck typing. 

> Which command line flag should be passed to gnu-which to trigger the version info? I was browsing through the source and it looks like it should accept -v or -V but I gather it doesn't?

I missexpressed myself:

default OSX `which` is **not** gnu-which. 
default OSX `which` has no flag to give its version. 
default OSX is stupid and kill kittens. 

OSX user **can** install gnu-witch, if they like, 
in which case `-v` is available. 

So we have 2 ways in from of us. One is a bridge made out of wood, and one out of stone.
- ~~turn user into a newt~~
- assume `-V` is never available on osx.
- run `which` without argument, and check for `gnu` in output. 
  - if it is in output, then we are lucky, user has installed `gnu-which`
  - if it is not, then out of luck, we are on default OSX `which`, and we have no way of knowing its version. 

Does that make more sens ? 

> default OSX is stupid and kill kittens. 

Burn it!

Got it.  I'll take a look at it.


Resolving patch:
diff --git a/xonsh/aliases.py b/xonsh/aliases.py
--- a/xonsh/aliases.py
+++ b/xonsh/aliases.py
@@ -328,6 +328,10 @@ def bang_bang(args, stdin=None):
 
 def which_version():
     """Returns output from system `which -v`"""
+    if sys.platform == 'darwin':
+        if ('gnu' not in subprocess.run(['which'], stderr=subprocess.PIPE).stderr.decode('utf-8')):
+            return '<no version number available on OS X>'
+
     _ver = subprocess.run(['which','-v'], stdout=subprocess.PIPE)
     return(_ver.stdout.decode('utf-8'))
 


Test patch:
Repository: xonsh/xonsh

Issue:
Tab completion on __xonsh_shell__.shell. fails
[See this mailing list discussion.](https://groups.google.com/d/msgid/xonsh/eb9b3b50-33c0-4652-949b-f042ec160f78%40googlegroups.com?utm_medium=email&utm_source=footer) I think that this is caused by the coloring code being updated and something in the completions not taking this into account.



Discussion:
Yes, interesting.  I use the readline shell and can confirm it isn't happening there (seems to be PTK only).

I bet this is because the Shell class does some weird redirection stuff to its `shell` attr, which is an instance of one of the concrete shell types. 


Resolving patch:
diff --git a/xonsh/base_shell.py b/xonsh/base_shell.py
--- a/xonsh/base_shell.py
+++ b/xonsh/base_shell.py
@@ -12,7 +12,7 @@
                              code_cache_check, get_cache_filename,
                              update_cache, run_compiled_code)
 from xonsh.completer import Completer
-from xonsh.environ import multiline_prompt, format_prompt
+from xonsh.environ import multiline_prompt, format_prompt, partial_format_prompt
 if HAVE_PYGMENTS:
     from xonsh.pyghooks import XonshStyle
 
@@ -246,7 +246,7 @@ def prompt(self):
         env = builtins.__xonsh_env__  # pylint: disable=no-member
         p = env.get('PROMPT')
         try:
-            p = format_prompt(p)
+            p = partial_format_prompt(p)
         except Exception:  # pylint: disable=broad-except
             print_exception()
         self.settitle()


Test patch:
Repository: xonsh/xonsh

Issue:
Segmentation faults and other special return codes should print corresponding messages
If an application like this:

``` c
int main() {
    char* p = 0;
    return *p; // Uh-oh!
}
```

segfaults, Bash shows the following:

```
ryan@DevPC-LX:~/langtest/xonsh$ ./seg
Segmentation fault (core dumped)
ryan@DevPC-LX:~/langtest/xonsh$ 
```

But Xonsh shows:

```
ryan@DevPC-LX ~/langtest/xonsh $ ./seg

ryan@DevPC-LX ~/langtest/xonsh $
```

See:

http://tldp.org/LDP/abs/html/exitcodes.html

and:

https://en.wikipedia.org/wiki/Unix_signal#POSIX_signals

Would you be interested in a pull request for this?

Segmentation faults and other special return codes should print corresponding messages
If an application like this:

``` c
int main() {
    char* p = 0;
    return *p; // Uh-oh!
}
```

segfaults, Bash shows the following:

```
ryan@DevPC-LX:~/langtest/xonsh$ ./seg
Segmentation fault (core dumped)
ryan@DevPC-LX:~/langtest/xonsh$ 
```

But Xonsh shows:

```
ryan@DevPC-LX ~/langtest/xonsh $ ./seg

ryan@DevPC-LX ~/langtest/xonsh $
```

See:

http://tldp.org/LDP/abs/html/exitcodes.html

and:

https://en.wikipedia.org/wiki/Unix_signal#POSIX_signals

Would you be interested in a pull request for this?



Discussion:
Thanks for pointing this out @kirbyfan64! We'd absolutely be interested in a PR to this effect.

Thanks for pointing this out @kirbyfan64! We'd absolutely be interested in a PR to this effect.


Resolving patch:
diff --git a/xonsh/built_ins.py b/xonsh/built_ins.py
--- a/xonsh/built_ins.py
+++ b/xonsh/built_ins.py
@@ -42,6 +42,17 @@
 if ON_POSIX:
     AT_EXIT_SIGNALS += (signal.SIGTSTP, signal.SIGQUIT, signal.SIGHUP)
 
+SIGNAL_MESSAGES = {
+    signal.SIGABRT: 'Aborted',
+    signal.SIGFPE: 'Floating point exception',
+    signal.SIGILL: 'Illegal instructions',
+    signal.SIGTERM: 'Terminated',
+    signal.SIGSEGV: 'Segmentation fault',
+    signal.SIGQUIT: 'Quit',
+    signal.SIGHUP: 'Hangup',
+    signal.SIGKILL: 'Killed'
+}
+
 
 def resetting_signal_handle(sig, f):
     """Sets a new signal handle that will automatically restore the old value
@@ -600,6 +611,13 @@ def run_subproc(cmds, captured=False):
                 errout = errout.replace('\r\n', '\n')
                 procinfo['stderr'] = errout
 
+    if getattr(prev_proc, 'signal', None):
+        sig, core = prev_proc.signal
+        sig_str = SIGNAL_MESSAGES.get(sig)
+        if sig_str:
+            if core:
+                sig_str += ' (core dumped)'
+            print(sig_str, file=sys.stderr)
     if (not prev_is_proxy and
             hist.last_cmd_rtn is not None and
             hist.last_cmd_rtn > 0 and


Test patch:
Repository: xonsh/xonsh

Issue:
Incorrect parsing of some command line flags
I first noticed this when `nosetests -q` didn't actually run with the `-q` option enabled.  It seems to affect other commands as well:

```
hartz@tabby-3 ~/xonsh $ rmdir --version
/bin/rmdir: failed to remove ‘-’: No such file or directory
```

Maybe this is a side-effect of the changes in #1029?



Discussion:
@adqm -- I just ran into this too.  bisection says it's from 45265f059

Other reasonably serious problems with it:

``` console
gil@bad_cat ~ $ mv .xonshrc.bak .xonshrc
/usr/bin/mv: missing destination file operand after '.xonshrc.bak'
Try '/usr/bin/mv --help' for more information.
```

``` console
gil@bad_cat ~/tmp $ ls
a_really_rather_long_dir_name  exists  inaccessible
bar                            foo
gil@bad_cat ~/tmp $ ls -a
a_really_rather_long_dir_name  exists  inaccessible
bar                            foo
gil@bad_cat ~/tmp $ ls -l
a_really_rather_long_dir_name  exists  inaccessible
bar 
```

vs

``` console
gil@bad_cat ~/tmp $ ls -l .
total 8
drwxr-xr-x 2 gil  users 4096 May 14 23:52 a_really_rather_long_dir_name
-rw-r--r-- 1 gil  users    0 May  8 15:19 bar
-rw-r--r-- 1 gil  users    0 May  8 15:19 exists
-rw-r--r-- 1 gil  users    0 May  8 15:19 foo
drwxr-x--- 2 root root  4096 May 26 10:54 inaccessible
gil@bad_cat ~/tmp $ ls -a .
.   .A                             bar     foo
..  a_really_rather_long_dir_name  exists  inaccessible
```

(note the trailing dot)

Wrapping the command in `$[]` works

Fix incoming...


Resolving patch:
diff --git a/xonsh/ast.py b/xonsh/ast.py
--- a/xonsh/ast.py
+++ b/xonsh/ast.py
@@ -157,7 +157,7 @@ def try_subproc_toks(self, node, strip_expr=False):
                 maxcol = find_next_break(line, mincol=mincol,
                                          lexer=self.parser.lexer)
             else:
-                maxcol + 1
+                maxcol += 1
         spline = subproc_toks(line,
                               mincol=mincol,
                               maxcol=maxcol,


Test patch:
Repository: xonsh/xonsh

Issue:
Configuration fails on Windows due to colon in filename
`xonfig wizard` fails on Windows because the temporary configuration file created has a colon in its filename.

The relevant output is:

```
Would you like to save this state, yes or no [default: no]? yes
filename [default='C:\\Users\\alowe\\.config\\xonsh\\config.json']:
Traceback (most recent call last):
  File "c:\users\alowe\appdata\local\continuum\anaconda3\lib\shutil.py", line 538, in move
    os.rename(src, real_dst)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'C:\\Users\\alowe\\.config\\xonsh\\config.json' -> 'C:\\Users\\alowe\\.config\\xonsh\\config.2016-06-08T11:18:52.170226.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\alowe\appdata\local\continuum\anaconda3\lib\site-packages\xonsh\xonfig.py", line 307, in _wizard
    pv.visit()
  File "c:\users\alowe\appdata\local\continuum\anaconda3\lib\site-packages\xonsh\wizard.py", line 481, in visit
    rtn = super().visit(node)
  File "c:\users\alowe\appdata\local\continuum\anaconda3\lib\site-packages\xonsh\wizard.py", line 302, in visit
    rtn = meth(node)
  File "c:\users\alowe\appdata\local\continuum\anaconda3\lib\site-packages\xonsh\wizard.py", line 538, in visit_wizard
    self.visit(child)
  File "c:\users\alowe\appdata\local\continuum\anaconda3\lib\site-packages\xonsh\wizard.py", line 481, in visit
    rtn = super().visit(node)
  File "c:\users\alowe\appdata\local\continuum\anaconda3\lib\site-packages\xonsh\wizard.py", line 302, in visit
    rtn = meth(node)
  File "c:\users\alowe\appdata\local\continuum\anaconda3\lib\site-packages\xonsh\wizard.py", line 623, in visit_save
    backup_file(fname)
  File "c:\users\alowe\appdata\local\continuum\anaconda3\lib\site-packages\xonsh\tools.py", line 1165, in backup_file
    shutil.move(fname, newfname)
  File "c:\users\alowe\appdata\local\continuum\anaconda3\lib\shutil.py", line 552, in move
    copy_function(src, real_dst)
  File "c:\users\alowe\appdata\local\continuum\anaconda3\lib\shutil.py", line 251, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "c:\users\alowe\appdata\local\continuum\anaconda3\lib\shutil.py", line 115, in copyfile
    with open(dst, 'wb') as fdst:
OSError: [Errno 22] Invalid argument: 'C:\\Users\\alowe\\.config\\xonsh\\config.2016-06-08T11:18:52.170226.json'
```



Discussion:

Resolving patch:
diff --git a/xonsh/tools.py b/xonsh/tools.py
--- a/xonsh/tools.py
+++ b/xonsh/tools.py
@@ -1171,7 +1171,8 @@ def backup_file(fname):
     import shutil
     from datetime import datetime
     base, ext = os.path.splitext(fname)
-    newfname = base + '.' + datetime.now().isoformat() + ext
+    timestamp = datetime.now().strftime('%Y-%m-%d-%H-%M-%S-%f')
+    newfname = '%s.%s%s' % (base, timestamp, ext)
     shutil.move(fname, newfname)
 
 


Test patch:
Repository: xonsh/xonsh

Issue:
xonfig broken on current master
```
$ xonfig
xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
  File "C:\Users\mel\Anaconda3\lib\site-packages\xonsh\proc.py", line 336, in wrapped_simple_command
    r = f(args, i)
  File "C:\Users\mel\Anaconda3\lib\site-packages\xonsh\aliases.py", line 453, in xonfig
    from xonsh.xonfig import main  # lazy import
ImportError: cannot import name 'main'
```



Discussion:
Yikes.  Also this:

``` console
$ xonfig
xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
  File "/home/gil/anaconda/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 10001, in wrapped_simple_command
    r = f(args, i)
  File "/home/gil/anaconda/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 13880, in xonfig
    return main(args)
  File "/home/gil/anaconda/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 15893, in main
    args = premain(argv)
  File "/home/gil/anaconda/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 15880, in premain
    shell = builtins.__xonsh_shell__ = Shell(**shell_kwargs)
  File "/home/gil/anaconda/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 15625, in __init__
    kwargs.get('cacheall', False))
  File "/home/gil/anaconda/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 15667, in _init_environ
    debug_level=debug)
  File "/home/gil/anaconda/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 15311, in __init__
    load_builtins(execer=self, config=config, login=login, ctx=xonsh_ctx)
  File "/home/gil/anaconda/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 15197, in load_builtins
    resetting_signal_handle(sig, _lastflush)
  File "/home/gil/anaconda/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 14550, in resetting_signal_handle
    signal.signal(sig, newh)
  File "/home/gil/anaconda/lib/python3.5/signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread
```

running xonfig twice gets even crazier :(

ooo, yikes.  yes it does

On it now.


Resolving patch:
diff --git a/xonsh/aliases.py b/xonsh/aliases.py
--- a/xonsh/aliases.py
+++ b/xonsh/aliases.py
@@ -450,8 +450,8 @@ def which(args, stdin=None, stdout=None, stderr=None):
 
 def xonfig(args, stdin=None):
     """Runs the xonsh configuration utility."""
-    from xonsh.xonfig import main  # lazy import
-    return main(args)
+    from xonsh.xonfig import xonfig_main  # lazy import
+    return xonfig_main(args)
 
 
 @foreground
diff --git a/xonsh/xonfig.py b/xonsh/xonfig.py
--- a/xonsh/xonfig.py
+++ b/xonsh/xonfig.py
@@ -353,7 +353,7 @@ def _info(ns):
         ('is superuser', is_superuser()),
         ('default encoding', DEFAULT_ENCODING),
         ])
-    formatter = _xonfig_format_json if ns.json else __xonfig_format_human
+    formatter = _xonfig_format_json if ns.json else _xonfig_format_human
     s = formatter(data)
     return s
 


Test patch:
Repository: xonsh/xonsh

Issue:
Amalgamate build on Anaconda.org fails
It builds fine on my machine so I am not really sure what is going on here: 

https://anaconda.org/xonsh/xonsh/builds/403/0

``` bash
+ python setup.py install --single-version-externally-managed --record=record.txt
Traceback (most recent call last):
  File "setup.py", line 210, in <module>
    main()
  File "setup.py", line 206, in main
    setup(**skw)
  File "/opt/miniconda/envs/_build/lib/python3.4/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/opt/miniconda/envs/_build/lib/python3.4/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/opt/miniconda/envs/_build/lib/python3.4/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "setup.py", line 99, in run
    build_tables()
  File "setup.py", line 59, in build_tables
    amalgamate.main(['amalgamate', '--debug=XONSH_DEBUG', 'xonsh'])
  File "/opt/miniconda/conda-bld/work/amalgamate.py", line 369, in main
    graph = make_graph(pkg, exclude=exclude)
  File "/opt/miniconda/conda-bld/work/amalgamate.py", line 94, in make_graph
    graph[base] = make_node(base, pkg, allowed)
  File "/opt/miniconda/conda-bld/work/amalgamate.py", line 54, in make_node
    raw = SOURCES[pkg, name]
  File "/opt/miniconda/conda-bld/work/amalgamate.py", line 39, in __getitem__
    raw = f.read()
  File "/opt/miniconda/envs/_build/lib/python3.4/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc7 in position 2102: ordinal not in range(128)
Command failed: /bin/bash -x -e /opt/miniconda/conda-bld/work/conda_build.sh
discarding /home/dev/env/bin from PATH

```



Discussion:

Resolving patch:
diff --git a/xonsh/platform.py b/xonsh/platform.py
--- a/xonsh/platform.py
+++ b/xonsh/platform.py
@@ -69,7 +69,7 @@ def _has_pygments():
 
 @functools.lru_cache(1)
 def pygments_version():
-    """pygments.__version__ version if available, else Ǹone."""
+    """pygments.__version__ version if available, else None."""
     if HAS_PYGMENTS:
         import pygments
         v = pygments.__version__


Test patch:
Repository: xonsh/xonsh

Issue:
xonfig --version and --help arguments error
```
> xonsh --version
('xonsh/0.3.4',)
Traceback (most recent call last):
  File "/usr/local/bin/xonsh", line 3, in <module>
    main()
  File "/usr/local/lib/python3.5/dist-packages/xonsh/__amalgam__.py", line 15893, in main
    args = premain(argv)
  File "/usr/local/lib/python3.5/dist-packages/xonsh/__amalgam__.py", line 15852, in premain
    exit()
TypeError: exit() missing 1 required positional argument: 'args'
```

same happens with --help options, it displays the help message and raises the same error



Discussion:

Resolving patch:
diff --git a/xonsh/aliases.py b/xonsh/aliases.py
--- a/xonsh/aliases.py
+++ b/xonsh/aliases.py
@@ -142,12 +142,11 @@ def _repr_pretty_(self, p, cycle):
 
 
 
-def exit(args, stdin=None):  # pylint:disable=redefined-builtin,W0622
+def xonsh_exit(args, stdin=None):
     """Sends signal to exit shell."""
     if not clean_jobs():
         # Do not exit if jobs not cleaned up
         return None, None
-
     builtins.__xonsh_exit__ = True
     print()  # gimme a newline
     return None, None
@@ -500,9 +499,9 @@ def make_default_aliases():
         'jobs': jobs,
         'fg': fg,
         'bg': bg,
-        'EOF': exit,
-        'exit': exit,
-        'quit': exit,
+        'EOF': xonsh_exit,
+        'exit': xonsh_exit,
+        'quit': xonsh_exit,
         'xexec': xexec,
         'source': source_alias,
         'source-zsh': ['source-foreign', 'zsh', '--sourcer=source'],
diff --git a/xonsh/ptk/key_bindings.py b/xonsh/ptk/key_bindings.py
--- a/xonsh/ptk/key_bindings.py
+++ b/xonsh/ptk/key_bindings.py
@@ -6,7 +6,7 @@
 from prompt_toolkit.filters import (Condition, Filter, IsMultiline,
                                     HasSelection)
 from prompt_toolkit.keys import Keys
-from xonsh.aliases import exit
+from xonsh.aliases import xonsh_exit
 from xonsh.tools import ON_WINDOWS
 
 env = builtins.__xonsh_env__
@@ -151,7 +151,7 @@ def call_exit_alias(event):
         """Use xonsh exit function"""
         b = event.cli.current_buffer
         b.accept_action.validate_and_handle(event.cli, b)
-        exit([])
+        xonsh_exit([])
 
     @handle(Keys.ControlJ, filter=IsMultiline())
     def multiline_carriage_return(event):


Test patch:
Repository: xonsh/xonsh

Issue:
xonsh wizard misleading
I think that the "Foreign shell setup" part of the configuration wizard is a little misleading. I think that a paste will explain what I mean:

```
[...]
                      Foreign Shell Setup
                      -------------------
The xonsh shell has the ability to interface with foreign shells such
as Bash, zsh, or fish.

For configuration, this means that xonsh can load the environment,
aliases, and functions specified in the config files of these shells.
Naturally, these shells must be available on the system to work.
Being able to share configuration (and source) from foreign shells
makes it easier to transition to and from xonsh.

Add a foreign shell, yes or no [default: no]? yes
shell name (e.g. bash): zsh
interactive shell [bool, default=True]:
login shell [bool, default=False]:
env command [str, default='env']:
alias command [str, default='alias']:
extra command line arguments [list of str, default=[]]:
current environment [dict, default=None]:
safely handle exceptions [bool, default=True]:
pre-command [str, default='']:
post-command [str, default='']:
foreign function command [str, default=None]:
source command [str, default=None]:

Add a foreign shell, yes or no [default: no]? yes
shell name (e.g. bash):
interactive shell [bool, default=True]:
login shell [bool, default=False]: KeyboardInterrupt
```

Initially I insert all the configuration for my external shell, and then I get the question "Add a foreign shell, yes or no?". In this moment I think that xonsh means "Do you want to save the data you entered?", but instead it means "Add **another** foreign shell?".

What do you think about it? Second question be "Add another foreign shell?" and maybe give a little "ok, config saved" message before that?



Discussion:
Hi @youtux - thanks for brining this up! Please feel free to open a PR with this change.


Resolving patch:
diff --git a/xonsh/xonfig.py b/xonsh/xonfig.py
--- a/xonsh/xonfig.py
+++ b/xonsh/xonfig.py
@@ -111,7 +111,7 @@
 
 def make_fs_wiz():
     """Makes the foreign shell part of the wizard."""
-    cond = wiz.create_truefalse_cond(prompt='Add a foreign shell, ' + wiz.YN)
+    cond = wiz.create_truefalse_cond(prompt='Add a new foreign shell, ' + wiz.YN)
     fs = wiz.While(cond=cond, body=[
         wiz.Input('shell name (e.g. bash): ',
                   path='/foreign_shells/{idx}/shell'),
@@ -148,7 +148,7 @@ def make_fs_wiz():
                           path='/foreign_shells/{idx}/funcscmd'),
         wiz.StoreNonEmpty("source command [str, default=None]: ",
                           path='/foreign_shells/{idx}/sourcer'),
-        wiz.Message(message='')  # inserts a newline
+        wiz.Message(message='Foreign shell added.\n')
         ])
     return fs
 


Test patch: