We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Syntax errors when using bashisms xontrib
At least making assignment statements and entering function definitions at the prompt is 
broken when using the included `bashisms` xontrib and prompt toolkit.

## xonfig

```
$ xonfig                                                                                         
+------------------+---------------------+
| xonsh            | 0.8.12              |
| Git SHA          | 3edd2df7            |
| Commit Date      | May 9 07:50:20 2019 |
| Python           | 3.7.3               |
| PLY              | 3.11                |
| have readline    | True                |
| prompt toolkit   | 2.0.9               |
| shell type       | prompt_toolkit2     |
| pygments         | 2.3.1               |
| on posix         | True                |
| on linux         | True                |
| distro           | ubuntu              |
| 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     |
+------------------+---------------------+

```

## Expected Behavior
I should be able to create new variables and function definitions, no sweat.

## Current Behavior

Things work fine until I start the shell with the xontrib `bashisms` loaded, or after I start the shell without it and load it later.

Assignment statements appear to go into multiline mode after hitting the return
key, and after a second return key, a stacktrace appears. The assignment
statement does not succeed.

Function definitions at the prompt result in an IndexError and the function is
not defined afterwards.

### Traceback (if applicable)

#### Assignment

```
$ a = 1                                                                                          
$ a                                                                                              
1
$ xontrib load bashisms                                                                          
$ b = 1 
..................................................                                                                                                
Traceback (most recent call last):
  File "/home/eddie/source/xonsh/xonsh/ptk2/shell.py", line 173, in _push
    code = self.execer.compile(src, mode="single", glbs=self.ctx, locs=None)
  File "/home/eddie/source/xonsh/xonsh/execer.py", line 135, in compile
    tree = self.parse(input, ctx, mode=mode, filename=filename, transform=transform)
  File "/home/eddie/source/xonsh/xonsh/execer.py", line 96, in parse
    tree, input = self._parse_ctx_free(input, mode=mode, filename=filename)
  File "/home/eddie/source/xonsh/xonsh/execer.py", line 235, in _parse_ctx_free
    raise original_error from None
  File "/home/eddie/source/xonsh/xonsh/execer.py", line 220, in _parse_ctx_free
    debug_level=(self.debug_level > 2),
  File "/home/eddie/source/xonsh/xonsh/parsers/base.py", line 543, in parse
    tree = self.parser.parse(input=s, lexer=self.lexer, debug=debug_level)
  File "/home/eddie/source/xonsh/xonsh/ply/ply/yacc.py", line 335, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "/home/eddie/source/xonsh/xonsh/ply/ply/yacc.py", line 1203, in parseopt_notrack
    tok = call_errorfunc(self.errorfunc, errtoken, self)
  File "/home/eddie/source/xonsh/xonsh/ply/ply/yacc.py", line 194, in call_errorfunc
    r = errorfunc(token)
  File "/home/eddie/source/xonsh/xonsh/parsers/base.py", line 3285, in p_error
    self._parse_error("no further code", None)
  File "/home/eddie/source/xonsh/xonsh/parsers/base.py", line 676, in _parse_error
    raise err
  File "<string>", line None
SyntaxError: None: no further code
$ b                                                                                              
Traceback (most recent call last):
  File "/home/eddie/source/xonsh/xonsh/built_ins.py", line 560, in _run_binary
    p = self.cls(self.cmd, bufsize=bufsize, **kwargs)
  File "/home/eddie/source/xonsh/xonsh/proc.py", line 583, in __init__
    *args, stdin=stdin, stdout=stdout, stderr=stderr, **kwargs
  File "/home/eddie/.pyenv/versions/3.7.3/lib/python3.7/subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "/home/eddie/.pyenv/versions/3.7.3/lib/python3.7/subprocess.py", line 1522, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'b': 'b'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/eddie/source/xonsh/xonsh/proc.py", line 1856, in __init__
    proc = spec.run(pipeline_group=pipeline_group)
  File "/home/eddie/source/xonsh/xonsh/built_ins.py", line 549, in run
    p = self._run_binary(kwargs)
  File "/home/eddie/source/xonsh/xonsh/built_ins.py", line 571, in _run_binary
    raise XonshError(e)
xonsh.tools.XonshError: xonsh: subprocess mode: command not found: b
Did you mean one of the following?
    bg:  Alias
    e:   Alias
    z:   Alias
    bc:  Command (/usr/bin/bc)
    ab:  Command (/usr/bin/ab)

b: command not found
```

#### Function definition

```
$ def f(): 
..................................................     pass 
..................................................                                                                                                
$ f                                                                                              
<function __main__.f>
$ xontrib load bashisms                                                                          
$ def g(): 
..................................................     pass 
..................................................                                                                                                
Traceback (most recent call last):
  File "/home/eddie/source/xonsh/xonsh/execer.py", line 220, in _parse_ctx_free
    debug_level=(self.debug_level > 2),
  File "/home/eddie/source/xonsh/xonsh/parsers/base.py", line 543, in parse
    tree = self.parser.parse(input=s, lexer=self.lexer, debug=debug_level)
  File "/home/eddie/source/xonsh/xonsh/ply/ply/yacc.py", line 335, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "/home/eddie/source/xonsh/xonsh/ply/ply/yacc.py", line 1203, in parseopt_notrack
    tok = call_errorfunc(self.errorfunc, errtoken, self)
  File "/home/eddie/source/xonsh/xonsh/ply/ply/yacc.py", line 194, in call_errorfunc
    r = errorfunc(token)
  File "/home/eddie/source/xonsh/xonsh/parsers/base.py", line 3295, in p_error
    self._parse_error(msg, self.currloc(lineno=p.lineno, column=p.lexpos))
  File "/home/eddie/source/xonsh/xonsh/parsers/base.py", line 676, in _parse_error
    raise err
  File "<string>", line None
SyntaxError: /home/eddie/source/xonsh/xontrib/prompt_ret_code.xsh:3:0: ('code: ',)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/eddie/source/xonsh/xonsh/ptk2/shell.py", line 173, in _push
    code = self.execer.compile(src, mode="single", glbs=self.ctx, locs=None)
  File "/home/eddie/source/xonsh/xonsh/execer.py", line 135, in compile
    tree = self.parse(input, ctx, mode=mode, filename=filename, transform=transform)
  File "/home/eddie/source/xonsh/xonsh/execer.py", line 96, in parse
    tree, input = self._parse_ctx_free(input, mode=mode, filename=filename)
  File "/home/eddie/source/xonsh/xonsh/execer.py", line 242, in _parse_ctx_free
    line, nlogical, idx = get_logical_line(lines, idx)
  File "/home/eddie/source/xonsh/xonsh/tools.py", line 544, in get_logical_line
    line = lines[idx]
IndexError: list index out of range
$ g                                                                                              
Traceback (most recent call last):
  File "/home/eddie/source/xonsh/xonsh/built_ins.py", line 560, in _run_binary
    p = self.cls(self.cmd, bufsize=bufsize, **kwargs)
  File "/home/eddie/source/xonsh/xonsh/proc.py", line 583, in __init__
    *args, stdin=stdin, stdout=stdout, stderr=stderr, **kwargs
  File "/home/eddie/.pyenv/versions/3.7.3/lib/python3.7/subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "/home/eddie/.pyenv/versions/3.7.3/lib/python3.7/subprocess.py", line 1522, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'g': 'g'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/eddie/source/xonsh/xonsh/proc.py", line 1856, in __init__
    proc = spec.run(pipeline_group=pipeline_group)
  File "/home/eddie/source/xonsh/xonsh/built_ins.py", line 549, in run
    p = self._run_binary(kwargs)
  File "/home/eddie/source/xonsh/xonsh/built_ins.py", line 571, in _run_binary
    raise XonshError(e)
xonsh.tools.XonshError: xonsh: subprocess mode: command not found: g
Did you mean one of the following?
    fg:  Alias
    bg:  Alias
    e:   Alias
    z:   Alias
    ag:  Command (/usr/local/bin/ag)

g: command not found
```

## Steps to Reproduce

```
# start w/o bashisms loaded
$ a = 1                                                                                      
$ xontrib load bashisms                                                                      
$ a = 1 
```

or

```
# start w/o bashisms loaded
$ xontrib load bashisms                                                                      
$ def f(): 
..................................................     pass 
..................................................          
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `xontrib/bashisms.py`
Content:
```
1 """Bash-like interface extensions for xonsh."""
2 import shlex
3 import sys
4 import re
5 
6 from prompt_toolkit.keys import Keys
7 from prompt_toolkit.filters import Condition, EmacsInsertMode, ViInsertMode
8 
9 from xonsh.platform import ptk_shell_type
10 
11 __all__ = ()
12 
13 
14 @events.on_transform_command
15 def bash_preproc(cmd, **kw):
16     bang_previous = {
17         "!": lambda x: x,
18         "$": lambda x: shlex.split(x)[-1],
19         "^": lambda x: shlex.split(x)[0],
20         "*": lambda x: " ".join(shlex.split(x)[1:]),
21     }
22 
23     def replace_bang(m):
24         arg = m.group(1)
25         inputs = __xonsh__.history.inps
26 
27         # Dissect the previous command.
28         if arg in bang_previous:
29             try:
30                 return bang_previous[arg](inputs[-1])
31             except IndexError:
32                 print("xonsh: no history for '!{}'".format(arg))
33                 return ""
34 
35         # Look back in history for a matching command.
36         else:
37             try:
38                 return next((x for x in reversed(inputs) if x.startswith(arg)))
39             except StopIteration:
40                 print("xonsh: no previous commands match '!{}'".format(arg))
41                 return ""
42 
43     return re.sub(r"!([!$^*]|[\w]+)", replace_bang, cmd.strip())
44 
45 
46 @events.on_ptk_create
47 def custom_keybindings(bindings, **kw):
48     if ptk_shell_type() == "prompt_toolkit2":
49         handler = bindings.add
50 
51         @Condition
52         def last_command_exists():
53             return len(__xonsh__.history) > 0
54 
55     else:
56         handler = bindings.registry.add_binding
57 
58         @Condition
59         def last_command_exists(cli):
60             return len(__xonsh__.history) > 0
61 
62     insert_mode = ViInsertMode() | EmacsInsertMode()
63 
64     @handler(Keys.Escape, ".", filter=last_command_exists & insert_mode)
65     def recall_last_arg(event):
66         arg = __xonsh__.history[-1].cmd.split()[-1]
67         event.current_buffer.insert_text(arg)
68 
69 
70 def alias(args, stdin=None):
71     ret = 0
72 
73     if args:
74         for arg in args:
75             if "=" in arg:
76                 # shlex.split to remove quotes, e.g. "foo='echo hey'" into
77                 # "foo=echo hey"
78                 name, cmd = shlex.split(arg)[0].split("=", 1)
79                 aliases[name] = shlex.split(cmd)
80             elif arg in aliases:
81                 print("{}={}".format(arg, aliases[arg]))
82             else:
83                 print("alias: {}: not found".format(arg), file=sys.stderr)
84                 ret = 1
85     else:
86         for alias, cmd in aliases.items():
87             print("{}={}".format(alias, cmd))
88 
89     return ret
90 
91 
92 aliases["alias"] = alias
93
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/xontrib/bashisms.py b/xontrib/bashisms.py
--- a/xontrib/bashisms.py
+++ b/xontrib/bashisms.py
@@ -40,7 +40,7 @@
                 print("xonsh: no previous commands match '!{}'".format(arg))
                 return ""
 
-    return re.sub(r"!([!$^*]|[\w]+)", replace_bang, cmd.strip())
+    return re.sub(r"!([!$^*]|[\w]+)", replace_bang, cmd)
 
 
 @events.on_ptk_create

{"golden_diff": "diff --git a/xontrib/bashisms.py b/xontrib/bashisms.py\n--- a/xontrib/bashisms.py\n+++ b/xontrib/bashisms.py\n@@ -40,7 +40,7 @@\n                 print(\"xonsh: no previous commands match '!{}'\".format(arg))\n                 return \"\"\n \n-    return re.sub(r\"!([!$^*]|[\\w]+)\", replace_bang, cmd.strip())\n+    return re.sub(r\"!([!$^*]|[\\w]+)\", replace_bang, cmd)\n \n \n @events.on_ptk_create\n", "issue": "Syntax errors when using bashisms xontrib\nAt least making assignment statements and entering function definitions at the prompt is \r\nbroken when using the included `bashisms` xontrib and prompt toolkit.\r\n\r\n## xonfig\r\n\r\n```\r\n$ xonfig                                                                                         \r\n+------------------+---------------------+\r\n| xonsh            | 0.8.12              |\r\n| Git SHA          | 3edd2df7            |\r\n| Commit Date      | May 9 07:50:20 2019 |\r\n| Python           | 3.7.3               |\r\n| PLY              | 3.11                |\r\n| have readline    | True                |\r\n| prompt toolkit   | 2.0.9               |\r\n| shell type       | prompt_toolkit2     |\r\n| pygments         | 2.3.1               |\r\n| on posix         | True                |\r\n| on linux         | True                |\r\n| distro           | ubuntu              |\r\n| on darwin        | False               |\r\n| on windows       | False               |\r\n| on cygwin        | False               |\r\n| on msys2         | False               |\r\n| is superuser     | False               |\r\n| default encoding | utf-8               |\r\n| xonsh encoding   | utf-8               |\r\n| encoding errors  | surrogateescape     |\r\n+------------------+---------------------+\r\n\r\n```\r\n\r\n## Expected Behavior\r\nI should be able to create new variables and function definitions, no sweat.\r\n\r\n## Current Behavior\r\n\r\nThings work fine until I start the shell with the xontrib `bashisms` loaded, or after I start the shell without it and load it later.\r\n\r\nAssignment statements appear to go into multiline mode after hitting the return\r\nkey, and after a second return key, a stacktrace appears. The assignment\r\nstatement does not succeed.\r\n\r\nFunction definitions at the prompt result in an IndexError and the function is\r\nnot defined afterwards.\r\n\r\n### Traceback (if applicable)\r\n\r\n#### Assignment\r\n\r\n```\r\n$ a = 1                                                                                          \r\n$ a                                                                                              \r\n1\r\n$ xontrib load bashisms                                                                          \r\n$ b = 1 \r\n..................................................                                                                                                \r\nTraceback (most recent call last):\r\n  File \"/home/eddie/source/xonsh/xonsh/ptk2/shell.py\", line 173, in _push\r\n    code = self.execer.compile(src, mode=\"single\", glbs=self.ctx, locs=None)\r\n  File \"/home/eddie/source/xonsh/xonsh/execer.py\", line 135, in compile\r\n    tree = self.parse(input, ctx, mode=mode, filename=filename, transform=transform)\r\n  File \"/home/eddie/source/xonsh/xonsh/execer.py\", line 96, in parse\r\n    tree, input = self._parse_ctx_free(input, mode=mode, filename=filename)\r\n  File \"/home/eddie/source/xonsh/xonsh/execer.py\", line 235, in _parse_ctx_free\r\n    raise original_error from None\r\n  File \"/home/eddie/source/xonsh/xonsh/execer.py\", line 220, in _parse_ctx_free\r\n    debug_level=(self.debug_level > 2),\r\n  File \"/home/eddie/source/xonsh/xonsh/parsers/base.py\", line 543, in parse\r\n    tree = self.parser.parse(input=s, lexer=self.lexer, debug=debug_level)\r\n  File \"/home/eddie/source/xonsh/xonsh/ply/ply/yacc.py\", line 335, in parse\r\n    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)\r\n  File \"/home/eddie/source/xonsh/xonsh/ply/ply/yacc.py\", line 1203, in parseopt_notrack\r\n    tok = call_errorfunc(self.errorfunc, errtoken, self)\r\n  File \"/home/eddie/source/xonsh/xonsh/ply/ply/yacc.py\", line 194, in call_errorfunc\r\n    r = errorfunc(token)\r\n  File \"/home/eddie/source/xonsh/xonsh/parsers/base.py\", line 3285, in p_error\r\n    self._parse_error(\"no further code\", None)\r\n  File \"/home/eddie/source/xonsh/xonsh/parsers/base.py\", line 676, in _parse_error\r\n    raise err\r\n  File \"<string>\", line None\r\nSyntaxError: None: no further code\r\n$ b                                                                                              \r\nTraceback (most recent call last):\r\n  File \"/home/eddie/source/xonsh/xonsh/built_ins.py\", line 560, in _run_binary\r\n    p = self.cls(self.cmd, bufsize=bufsize, **kwargs)\r\n  File \"/home/eddie/source/xonsh/xonsh/proc.py\", line 583, in __init__\r\n    *args, stdin=stdin, stdout=stdout, stderr=stderr, **kwargs\r\n  File \"/home/eddie/.pyenv/versions/3.7.3/lib/python3.7/subprocess.py\", line 775, in __init__\r\n    restore_signals, start_new_session)\r\n  File \"/home/eddie/.pyenv/versions/3.7.3/lib/python3.7/subprocess.py\", line 1522, in _execute_child\r\n    raise child_exception_type(errno_num, err_msg, err_filename)\r\nFileNotFoundError: [Errno 2] No such file or directory: 'b': 'b'\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"/home/eddie/source/xonsh/xonsh/proc.py\", line 1856, in __init__\r\n    proc = spec.run(pipeline_group=pipeline_group)\r\n  File \"/home/eddie/source/xonsh/xonsh/built_ins.py\", line 549, in run\r\n    p = self._run_binary(kwargs)\r\n  File \"/home/eddie/source/xonsh/xonsh/built_ins.py\", line 571, in _run_binary\r\n    raise XonshError(e)\r\nxonsh.tools.XonshError: xonsh: subprocess mode: command not found: b\r\nDid you mean one of the following?\r\n    bg:  Alias\r\n    e:   Alias\r\n    z:   Alias\r\n    bc:  Command (/usr/bin/bc)\r\n    ab:  Command (/usr/bin/ab)\r\n\r\nb: command not found\r\n```\r\n\r\n#### Function definition\r\n\r\n```\r\n$ def f(): \r\n..................................................     pass \r\n..................................................                                                                                                \r\n$ f                                                                                              \r\n<function __main__.f>\r\n$ xontrib load bashisms                                                                          \r\n$ def g(): \r\n..................................................     pass \r\n..................................................                                                                                                \r\nTraceback (most recent call last):\r\n  File \"/home/eddie/source/xonsh/xonsh/execer.py\", line 220, in _parse_ctx_free\r\n    debug_level=(self.debug_level > 2),\r\n  File \"/home/eddie/source/xonsh/xonsh/parsers/base.py\", line 543, in parse\r\n    tree = self.parser.parse(input=s, lexer=self.lexer, debug=debug_level)\r\n  File \"/home/eddie/source/xonsh/xonsh/ply/ply/yacc.py\", line 335, in parse\r\n    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)\r\n  File \"/home/eddie/source/xonsh/xonsh/ply/ply/yacc.py\", line 1203, in parseopt_notrack\r\n    tok = call_errorfunc(self.errorfunc, errtoken, self)\r\n  File \"/home/eddie/source/xonsh/xonsh/ply/ply/yacc.py\", line 194, in call_errorfunc\r\n    r = errorfunc(token)\r\n  File \"/home/eddie/source/xonsh/xonsh/parsers/base.py\", line 3295, in p_error\r\n    self._parse_error(msg, self.currloc(lineno=p.lineno, column=p.lexpos))\r\n  File \"/home/eddie/source/xonsh/xonsh/parsers/base.py\", line 676, in _parse_error\r\n    raise err\r\n  File \"<string>\", line None\r\nSyntaxError: /home/eddie/source/xonsh/xontrib/prompt_ret_code.xsh:3:0: ('code: ',)\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"/home/eddie/source/xonsh/xonsh/ptk2/shell.py\", line 173, in _push\r\n    code = self.execer.compile(src, mode=\"single\", glbs=self.ctx, locs=None)\r\n  File \"/home/eddie/source/xonsh/xonsh/execer.py\", line 135, in compile\r\n    tree = self.parse(input, ctx, mode=mode, filename=filename, transform=transform)\r\n  File \"/home/eddie/source/xonsh/xonsh/execer.py\", line 96, in parse\r\n    tree, input = self._parse_ctx_free(input, mode=mode, filename=filename)\r\n  File \"/home/eddie/source/xonsh/xonsh/execer.py\", line 242, in _parse_ctx_free\r\n    line, nlogical, idx = get_logical_line(lines, idx)\r\n  File \"/home/eddie/source/xonsh/xonsh/tools.py\", line 544, in get_logical_line\r\n    line = lines[idx]\r\nIndexError: list index out of range\r\n$ g                                                                                              \r\nTraceback (most recent call last):\r\n  File \"/home/eddie/source/xonsh/xonsh/built_ins.py\", line 560, in _run_binary\r\n    p = self.cls(self.cmd, bufsize=bufsize, **kwargs)\r\n  File \"/home/eddie/source/xonsh/xonsh/proc.py\", line 583, in __init__\r\n    *args, stdin=stdin, stdout=stdout, stderr=stderr, **kwargs\r\n  File \"/home/eddie/.pyenv/versions/3.7.3/lib/python3.7/subprocess.py\", line 775, in __init__\r\n    restore_signals, start_new_session)\r\n  File \"/home/eddie/.pyenv/versions/3.7.3/lib/python3.7/subprocess.py\", line 1522, in _execute_child\r\n    raise child_exception_type(errno_num, err_msg, err_filename)\r\nFileNotFoundError: [Errno 2] No such file or directory: 'g': 'g'\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"/home/eddie/source/xonsh/xonsh/proc.py\", line 1856, in __init__\r\n    proc = spec.run(pipeline_group=pipeline_group)\r\n  File \"/home/eddie/source/xonsh/xonsh/built_ins.py\", line 549, in run\r\n    p = self._run_binary(kwargs)\r\n  File \"/home/eddie/source/xonsh/xonsh/built_ins.py\", line 571, in _run_binary\r\n    raise XonshError(e)\r\nxonsh.tools.XonshError: xonsh: subprocess mode: command not found: g\r\nDid you mean one of the following?\r\n    fg:  Alias\r\n    bg:  Alias\r\n    e:   Alias\r\n    z:   Alias\r\n    ag:  Command (/usr/local/bin/ag)\r\n\r\ng: command not found\r\n```\r\n\r\n## Steps to Reproduce\r\n\r\n```\r\n# start w/o bashisms loaded\r\n$ a = 1                                                                                      \r\n$ xontrib load bashisms                                                                      \r\n$ a = 1 \r\n```\r\n\r\nor\r\n\r\n```\r\n# start w/o bashisms loaded\r\n$ xontrib load bashisms                                                                      \r\n$ def f(): \r\n..................................................     pass \r\n..................................................          \r\n```\n", "before_files": [{"content": "\"\"\"Bash-like interface extensions for xonsh.\"\"\"\nimport shlex\nimport sys\nimport re\n\nfrom prompt_toolkit.keys import Keys\nfrom prompt_toolkit.filters import Condition, EmacsInsertMode, ViInsertMode\n\nfrom xonsh.platform import ptk_shell_type\n\n__all__ = ()\n\n\n@events.on_transform_command\ndef bash_preproc(cmd, **kw):\n    bang_previous = {\n        \"!\": lambda x: x,\n        \"$\": lambda x: shlex.split(x)[-1],\n        \"^\": lambda x: shlex.split(x)[0],\n        \"*\": lambda x: \" \".join(shlex.split(x)[1:]),\n    }\n\n    def replace_bang(m):\n        arg = m.group(1)\n        inputs = __xonsh__.history.inps\n\n        # Dissect the previous command.\n        if arg in bang_previous:\n            try:\n                return bang_previous[arg](inputs[-1])\n            except IndexError:\n                print(\"xonsh: no history for '!{}'\".format(arg))\n                return \"\"\n\n        # Look back in history for a matching command.\n        else:\n            try:\n                return next((x for x in reversed(inputs) if x.startswith(arg)))\n            except StopIteration:\n                print(\"xonsh: no previous commands match '!{}'\".format(arg))\n                return \"\"\n\n    return re.sub(r\"!([!$^*]|[\\w]+)\", replace_bang, cmd.strip())\n\n\n@events.on_ptk_create\ndef custom_keybindings(bindings, **kw):\n    if ptk_shell_type() == \"prompt_toolkit2\":\n        handler = bindings.add\n\n        @Condition\n        def last_command_exists():\n            return len(__xonsh__.history) > 0\n\n    else:\n        handler = bindings.registry.add_binding\n\n        @Condition\n        def last_command_exists(cli):\n            return len(__xonsh__.history) > 0\n\n    insert_mode = ViInsertMode() | EmacsInsertMode()\n\n    @handler(Keys.Escape, \".\", filter=last_command_exists & insert_mode)\n    def recall_last_arg(event):\n        arg = __xonsh__.history[-1].cmd.split()[-1]\n        event.current_buffer.insert_text(arg)\n\n\ndef alias(args, stdin=None):\n    ret = 0\n\n    if args:\n        for arg in args:\n            if \"=\" in arg:\n                # shlex.split to remove quotes, e.g. \"foo='echo hey'\" into\n                # \"foo=echo hey\"\n                name, cmd = shlex.split(arg)[0].split(\"=\", 1)\n                aliases[name] = shlex.split(cmd)\n            elif arg in aliases:\n                print(\"{}={}\".format(arg, aliases[arg]))\n            else:\n                print(\"alias: {}: not found\".format(arg), file=sys.stderr)\n                ret = 1\n    else:\n        for alias, cmd in aliases.items():\n            print(\"{}={}\".format(alias, cmd))\n\n    return ret\n\n\naliases[\"alias\"] = alias\n", "path": "xontrib/bashisms.py"}], "after_files": [{"content": "\"\"\"Bash-like interface extensions for xonsh.\"\"\"\nimport shlex\nimport sys\nimport re\n\nfrom prompt_toolkit.keys import Keys\nfrom prompt_toolkit.filters import Condition, EmacsInsertMode, ViInsertMode\n\nfrom xonsh.platform import ptk_shell_type\n\n__all__ = ()\n\n\n@events.on_transform_command\ndef bash_preproc(cmd, **kw):\n    bang_previous = {\n        \"!\": lambda x: x,\n        \"$\": lambda x: shlex.split(x)[-1],\n        \"^\": lambda x: shlex.split(x)[0],\n        \"*\": lambda x: \" \".join(shlex.split(x)[1:]),\n    }\n\n    def replace_bang(m):\n        arg = m.group(1)\n        inputs = __xonsh__.history.inps\n\n        # Dissect the previous command.\n        if arg in bang_previous:\n            try:\n                return bang_previous[arg](inputs[-1])\n            except IndexError:\n                print(\"xonsh: no history for '!{}'\".format(arg))\n                return \"\"\n\n        # Look back in history for a matching command.\n        else:\n            try:\n                return next((x for x in reversed(inputs) if x.startswith(arg)))\n            except StopIteration:\n                print(\"xonsh: no previous commands match '!{}'\".format(arg))\n                return \"\"\n\n    return re.sub(r\"!([!$^*]|[\\w]+)\", replace_bang, cmd)\n\n\n@events.on_ptk_create\ndef custom_keybindings(bindings, **kw):\n    if ptk_shell_type() == \"prompt_toolkit2\":\n        handler = bindings.add\n\n        @Condition\n        def last_command_exists():\n            return len(__xonsh__.history) > 0\n\n    else:\n        handler = bindings.registry.add_binding\n\n        @Condition\n        def last_command_exists(cli):\n            return len(__xonsh__.history) > 0\n\n    insert_mode = ViInsertMode() | EmacsInsertMode()\n\n    @handler(Keys.Escape, \".\", filter=last_command_exists & insert_mode)\n    def recall_last_arg(event):\n        arg = __xonsh__.history[-1].cmd.split()[-1]\n        event.current_buffer.insert_text(arg)\n\n\ndef alias(args, stdin=None):\n    ret = 0\n\n    if args:\n        for arg in args:\n            if \"=\" in arg:\n                # shlex.split to remove quotes, e.g. \"foo='echo hey'\" into\n                # \"foo=echo hey\"\n                name, cmd = shlex.split(arg)[0].split(\"=\", 1)\n                aliases[name] = shlex.split(cmd)\n            elif arg in aliases:\n                print(\"{}={}\".format(arg, aliases[arg]))\n            else:\n                print(\"alias: {}: not found\".format(arg), file=sys.stderr)\n                ret = 1\n    else:\n        for alias, cmd in aliases.items():\n            print(\"{}={}\".format(alias, cmd))\n\n    return ret\n\n\naliases[\"alias\"] = alias\n", "path": "xontrib/bashisms.py"}]}