We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
pipenv shell does not work when running Git for Windows' bash on Windows
##### Issue description

Running `pipenv shell` on windows when running bash in Git for Windows does not activate the virtual env successfully. It appears the actual activate script with the correct values is not being used.

##### Expected result

I would successfully be in the virtualenv

##### Actual result

The `VIRTUAL_ENV` and `PATH` variables are in the `C:` notation instead of `/c/` notation which would have worked.

```
declare -x VIRTUAL_ENV="C:\\Users\\user\\.virtualenvs\\project-OJ2s3Ey8"
declare -x PATH="C:/Users/user/.virtualenvs/project-OJ2s3Ey8/Scripts:/c/Users/user/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/usr/bin:/mingw64/bin:/usr/bin:/c/Users/andy/bin:/c/Python37/Scripts:/c/Python37" etc...
```

Sourcing the virtualenv activate variable does work, even though Git for Windows uses `msys` and not `cygwin`. Did not test cygwin

##### Steps to replicate

1. `pipenv install sphinx`
1. `echo $$`
1. `pipenv shell`
1. `echo $$`
1. `pip freeze`
1. `echo $PATH`

Shows that the pip environment is the original python environment, not the virtualenv. The different pid verifies that a new shell is indeed being run, but the virtualenv is not activating

Also tried

1. `PIPENV_EMULATOR=bash pipenv shell`

Identical results

<details><summary>$ pipenv --support</summary>

Pipenv version: `'2018.7.1'`

Pipenv location: `'c:\\python37\\lib\\site-packages\\pipenv'`

Python location: `'c:\\python37\\python.exe'`

Other Python installations in `PATH`:

  - `3.7`: `C:\Python37\python.exe`

  - `3.7.0`: `C:\Python37\python.exe`
  - `3.7.0`: `C:\Windows\py.exe`

PEP 508 Information:

```
{'implementation_name': 'cpython',
 'implementation_version': '3.7.0',
 'os_name': 'nt',
 'platform_machine': 'AMD64',
 'platform_python_implementation': 'CPython',
 'platform_release': '10',
 'platform_system': 'Windows',
 'platform_version': '10.0.17134',
 'python_full_version': '3.7.0',
 'python_version': '3.7',
 'sys_platform': 'win32'}
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pipenv/shells.py`
Content:
```
1 import collections
2 import contextlib
3 import os
4 import signal
5 import subprocess
6 import sys
7 
8 from ._compat import get_terminal_size, Path
9 from .environments import PIPENV_SHELL_EXPLICIT, PIPENV_SHELL, PIPENV_EMULATOR
10 from .utils import temp_environ
11 from .vendor import shellingham
12 
13 
14 ShellDetectionFailure = shellingham.ShellDetectionFailure
15 
16 
17 def _build_info(value):
18     return (os.path.splitext(os.path.basename(value))[0], value)
19 
20 
21 def detect_info():
22     if PIPENV_SHELL_EXPLICIT:
23         return _build_info(PIPENV_SHELL_EXPLICIT)
24     try:
25         return shellingham.detect_shell()
26     except (shellingham.ShellDetectionFailure, TypeError):
27         if PIPENV_SHELL:
28             return _build_info(PIPENV_SHELL)
29     raise ShellDetectionFailure
30 
31 
32 def _get_activate_script(venv):
33     """Returns the string to activate a virtualenv.
34 
35     This is POSIX-only at the moment since the compat (pexpect-based) shell
36     does not work elsewhere anyway.
37     """
38     # Suffix and source command for other shells.
39     # Support for fish shell.
40     if PIPENV_SHELL and "fish" in PIPENV_SHELL:
41         suffix = ".fish"
42         command = "source"
43     # Support for csh shell.
44     elif PIPENV_SHELL and "csh" in PIPENV_SHELL:
45         suffix = ".csh"
46         command = "source"
47     else:
48         suffix = ""
49         command = "."
50     # Escape any spaces located within the virtualenv path to allow
51     # for proper activation.
52     venv_location = str(venv).replace(" ", r"\ ")
53     # The leading space can make history cleaner in some shells.
54     return " {2} {0}/bin/activate{1}".format(venv_location, suffix, command)
55 
56 
57 def _handover(cmd, args):
58     args = [cmd] + args
59     if os.name != "nt":
60         os.execvp(cmd, args)
61     else:
62         sys.exit(subprocess.call(args, shell=True, universal_newlines=True))
63 
64 
65 class Shell(object):
66     def __init__(self, cmd):
67         self.cmd = cmd
68         self.args = []
69 
70     def __repr__(self):
71         return '{type}(cmd={cmd!r})'.format(
72             type=type(self).__name__,
73             cmd=self.cmd,
74         )
75 
76     @contextlib.contextmanager
77     def inject_path(self, venv):
78         with temp_environ():
79             os.environ["PATH"] = "{0}{1}{2}".format(
80                 os.pathsep.join(str(p.parent) for p in _iter_python(venv)),
81                 os.pathsep,
82                 os.environ["PATH"],
83             )
84             yield
85 
86     def fork(self, venv, cwd, args):
87         # FIXME: This isn't necessarily the correct prompt. We should read the
88         # actual prompt by peeking into the activation script.
89         name = os.path.basename(venv)
90         os.environ["VIRTUAL_ENV"] = str(venv)
91         if "PROMPT" in os.environ:
92             os.environ["PROMPT"] = "({0}) {1}".format(name, os.environ["PROMPT"])
93         if "PS1" in os.environ:
94             os.environ["PS1"] = "({0}) {1}".format(name, os.environ["PS1"])
95         with self.inject_path(venv):
96             os.chdir(cwd)
97             _handover(self.cmd, self.args + list(args))
98 
99     def fork_compat(self, venv, cwd, args):
100         from .vendor import pexpect
101 
102         # Grab current terminal dimensions to replace the hardcoded default
103         # dimensions of pexpect.
104         dims = get_terminal_size()
105         with temp_environ():
106             c = pexpect.spawn(self.cmd, ["-i"], dimensions=(dims.lines, dims.columns))
107         c.sendline(_get_activate_script(venv))
108         if args:
109             c.sendline(" ".join(args))
110 
111         # Handler for terminal resizing events
112         # Must be defined here to have the shell process in its context, since
113         # we can't pass it as an argument
114         def sigwinch_passthrough(sig, data):
115             dims = get_terminal_size()
116             c.setwinsize(dims.lines, dims.columns)
117 
118         signal.signal(signal.SIGWINCH, sigwinch_passthrough)
119 
120         # Interact with the new shell.
121         c.interact(escape_character=None)
122         c.close()
123         sys.exit(c.exitstatus)
124 
125 
126 POSSIBLE_ENV_PYTHON = [Path("bin", "python"), Path("Scripts", "python.exe")]
127 
128 
129 def _iter_python(venv):
130     for path in POSSIBLE_ENV_PYTHON:
131         full_path = Path(venv, path)
132         if full_path.is_file():
133             yield full_path
134 
135 
136 class Bash(Shell):
137     # The usual PATH injection technique does not work with Bash.
138     # https://github.com/berdario/pew/issues/58#issuecomment-102182346
139     @contextlib.contextmanager
140     def inject_path(self, venv):
141         from ._compat import NamedTemporaryFile
142 
143         bashrc_path = Path.home().joinpath(".bashrc")
144         with NamedTemporaryFile("w+") as rcfile:
145             if bashrc_path.is_file():
146                 base_rc_src = 'source "{0}"\n'.format(bashrc_path.as_posix())
147                 rcfile.write(base_rc_src)
148 
149             export_path = 'export PATH="{0}:$PATH"\n'.format(
150                 ":".join(python.parent.as_posix() for python in _iter_python(venv))
151             )
152             rcfile.write(export_path)
153             rcfile.flush()
154             self.args.extend(["--rcfile", rcfile.name])
155             yield
156 
157 
158 class CmderEmulatedShell(Shell):
159     def fork(self, venv, cwd, args):
160         if cwd:
161             os.environ["CMDER_START"] = cwd
162         super(CmderEmulatedShell, self).fork(venv, cwd, args)
163 
164 
165 class CmderCommandPrompt(CmderEmulatedShell):
166     def fork(self, venv, cwd, args):
167         rc = os.path.expandvars("%CMDER_ROOT%\\vendor\\init.bat")
168         if os.path.exists(rc):
169             self.args.extend(["/k", rc])
170         super(CmderCommandPrompt, self).fork(venv, cwd, args)
171 
172 
173 class CmderPowershell(Shell):
174     def fork(self, venv, cwd, args):
175         rc = os.path.expandvars("%CMDER_ROOT%\\vendor\\profile.ps1")
176         if os.path.exists(rc):
177             self.args.extend(
178                 [
179                     "-ExecutionPolicy",
180                     "Bypass",
181                     "-NoLogo",
182                     "-NoProfile",
183                     "-NoExit",
184                     "-Command",
185                     "Invoke-Expression '. ''{0}'''".format(rc),
186                 ]
187             )
188         super(CmderPowershell, self).fork(venv, cwd, args)
189 
190 
191 # Two dimensional dict. First is the shell type, second is the emulator type.
192 # Example: SHELL_LOOKUP['powershell']['cmder'] => CmderPowershell.
193 SHELL_LOOKUP = collections.defaultdict(
194     lambda: collections.defaultdict(lambda: Shell),
195     {
196         "bash": collections.defaultdict(lambda: Bash),
197         "cmd": collections.defaultdict(lambda: Shell, {"cmder": CmderCommandPrompt}),
198         "powershell": collections.defaultdict(
199             lambda: Shell, {"cmder": CmderPowershell}
200         ),
201         "pwsh": collections.defaultdict(lambda: Shell, {"cmder": CmderPowershell}),
202     },
203 )
204 
205 
206 def _detect_emulator():
207     if os.environ.get("CMDER_ROOT"):
208         return "cmder"
209     return ""
210 
211 
212 def choose_shell():
213     emulator = PIPENV_EMULATOR.lower() or _detect_emulator()
214     type_, command = detect_info()
215     return SHELL_LOOKUP[type_][emulator](command)
216
```
--- 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/pipenv/shells.py b/pipenv/shells.py
--- a/pipenv/shells.py
+++ b/pipenv/shells.py
@@ -134,6 +134,9 @@
 
 
 class Bash(Shell):
+    def _format_path(self, python):
+        return python.parent.as_posix()
+
     # The usual PATH injection technique does not work with Bash.
     # https://github.com/berdario/pew/issues/58#issuecomment-102182346
     @contextlib.contextmanager
@@ -146,15 +149,25 @@
                 base_rc_src = 'source "{0}"\n'.format(bashrc_path.as_posix())
                 rcfile.write(base_rc_src)
 
-            export_path = 'export PATH="{0}:$PATH"\n'.format(
-                ":".join(python.parent.as_posix() for python in _iter_python(venv))
-            )
+            export_path = 'export PATH="{0}:$PATH"\n'.format(":".join(
+                self._format_path(python)
+                for python in _iter_python(venv)
+            ))
             rcfile.write(export_path)
             rcfile.flush()
             self.args.extend(["--rcfile", rcfile.name])
             yield
 
 
+class MsysBash(Bash):
+    def _format_path(self, python):
+        s = super(MsysBash, self)._format_path(python)
+        if not python.drive:
+            return s
+        # Convert "C:/something" to "/c/something".
+        return '/{drive}{path}'.format(drive=s[0].lower(), path=s[2:])
+
+
 class CmderEmulatedShell(Shell):
     def fork(self, venv, cwd, args):
         if cwd:
@@ -193,23 +206,37 @@
 SHELL_LOOKUP = collections.defaultdict(
     lambda: collections.defaultdict(lambda: Shell),
     {
-        "bash": collections.defaultdict(lambda: Bash),
-        "cmd": collections.defaultdict(lambda: Shell, {"cmder": CmderCommandPrompt}),
+        "bash": collections.defaultdict(
+            lambda: Bash, {"msys": MsysBash},
+        ),
+        "cmd": collections.defaultdict(
+            lambda: Shell, {"cmder": CmderCommandPrompt},
+        ),
         "powershell": collections.defaultdict(
-            lambda: Shell, {"cmder": CmderPowershell}
+            lambda: Shell, {"cmder": CmderPowershell},
+        ),
+        "pwsh": collections.defaultdict(
+            lambda: Shell, {"cmder": CmderPowershell},
         ),
-        "pwsh": collections.defaultdict(lambda: Shell, {"cmder": CmderPowershell}),
     },
 )
 
 
 def _detect_emulator():
+    keys = []
     if os.environ.get("CMDER_ROOT"):
-        return "cmder"
-    return ""
+        keys.append("cmder")
+    if os.environ.get("MSYSTEM"):
+        keys.append("msys")
+    return ",".join(keys)
 
 
 def choose_shell():
     emulator = PIPENV_EMULATOR.lower() or _detect_emulator()
     type_, command = detect_info()
-    return SHELL_LOOKUP[type_][emulator](command)
+    shell_types = SHELL_LOOKUP[type_]
+    for key in emulator.split(","):
+        key = key.strip().lower()
+        if key in shell_types:
+            return shell_types[key](command)
+    return shell_types[""](command)

{"golden_diff": "diff --git a/pipenv/shells.py b/pipenv/shells.py\n--- a/pipenv/shells.py\n+++ b/pipenv/shells.py\n@@ -134,6 +134,9 @@\n \n \n class Bash(Shell):\n+    def _format_path(self, python):\n+        return python.parent.as_posix()\n+\n     # The usual PATH injection technique does not work with Bash.\n     # https://github.com/berdario/pew/issues/58#issuecomment-102182346\n     @contextlib.contextmanager\n@@ -146,15 +149,25 @@\n                 base_rc_src = 'source \"{0}\"\\n'.format(bashrc_path.as_posix())\n                 rcfile.write(base_rc_src)\n \n-            export_path = 'export PATH=\"{0}:$PATH\"\\n'.format(\n-                \":\".join(python.parent.as_posix() for python in _iter_python(venv))\n-            )\n+            export_path = 'export PATH=\"{0}:$PATH\"\\n'.format(\":\".join(\n+                self._format_path(python)\n+                for python in _iter_python(venv)\n+            ))\n             rcfile.write(export_path)\n             rcfile.flush()\n             self.args.extend([\"--rcfile\", rcfile.name])\n             yield\n \n \n+class MsysBash(Bash):\n+    def _format_path(self, python):\n+        s = super(MsysBash, self)._format_path(python)\n+        if not python.drive:\n+            return s\n+        # Convert \"C:/something\" to \"/c/something\".\n+        return '/{drive}{path}'.format(drive=s[0].lower(), path=s[2:])\n+\n+\n class CmderEmulatedShell(Shell):\n     def fork(self, venv, cwd, args):\n         if cwd:\n@@ -193,23 +206,37 @@\n SHELL_LOOKUP = collections.defaultdict(\n     lambda: collections.defaultdict(lambda: Shell),\n     {\n-        \"bash\": collections.defaultdict(lambda: Bash),\n-        \"cmd\": collections.defaultdict(lambda: Shell, {\"cmder\": CmderCommandPrompt}),\n+        \"bash\": collections.defaultdict(\n+            lambda: Bash, {\"msys\": MsysBash},\n+        ),\n+        \"cmd\": collections.defaultdict(\n+            lambda: Shell, {\"cmder\": CmderCommandPrompt},\n+        ),\n         \"powershell\": collections.defaultdict(\n-            lambda: Shell, {\"cmder\": CmderPowershell}\n+            lambda: Shell, {\"cmder\": CmderPowershell},\n+        ),\n+        \"pwsh\": collections.defaultdict(\n+            lambda: Shell, {\"cmder\": CmderPowershell},\n         ),\n-        \"pwsh\": collections.defaultdict(lambda: Shell, {\"cmder\": CmderPowershell}),\n     },\n )\n \n \n def _detect_emulator():\n+    keys = []\n     if os.environ.get(\"CMDER_ROOT\"):\n-        return \"cmder\"\n-    return \"\"\n+        keys.append(\"cmder\")\n+    if os.environ.get(\"MSYSTEM\"):\n+        keys.append(\"msys\")\n+    return \",\".join(keys)\n \n \n def choose_shell():\n     emulator = PIPENV_EMULATOR.lower() or _detect_emulator()\n     type_, command = detect_info()\n-    return SHELL_LOOKUP[type_][emulator](command)\n+    shell_types = SHELL_LOOKUP[type_]\n+    for key in emulator.split(\",\"):\n+        key = key.strip().lower()\n+        if key in shell_types:\n+            return shell_types[key](command)\n+    return shell_types[\"\"](command)\n", "issue": "pipenv shell does not work when running Git for Windows' bash on Windows\n##### Issue description\r\n\r\nRunning `pipenv shell` on windows when running bash in Git for Windows does not activate the virtual env successfully. It appears the actual activate script with the correct values is not being used.\r\n\r\n##### Expected result\r\n\r\nI would successfully be in the virtualenv\r\n\r\n##### Actual result\r\n\r\nThe `VIRTUAL_ENV` and `PATH` variables are in the `C:` notation instead of `/c/` notation which would have worked.\r\n\r\n```\r\ndeclare -x VIRTUAL_ENV=\"C:\\\\Users\\\\user\\\\.virtualenvs\\\\project-OJ2s3Ey8\"\r\ndeclare -x PATH=\"C:/Users/user/.virtualenvs/project-OJ2s3Ey8/Scripts:/c/Users/user/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/usr/bin:/mingw64/bin:/usr/bin:/c/Users/andy/bin:/c/Python37/Scripts:/c/Python37\" etc...\r\n```\r\n\r\nSourcing the virtualenv activate variable does work, even though Git for Windows uses `msys` and not `cygwin`. Did not test cygwin\r\n\r\n##### Steps to replicate\r\n\r\n1. `pipenv install sphinx`\r\n1. `echo $$`\r\n1. `pipenv shell`\r\n1. `echo $$`\r\n1. `pip freeze`\r\n1. `echo $PATH`\r\n\r\nShows that the pip environment is the original python environment, not the virtualenv. The different pid verifies that a new shell is indeed being run, but the virtualenv is not activating\r\n\r\nAlso tried\r\n\r\n1. `PIPENV_EMULATOR=bash pipenv shell`\r\n\r\nIdentical results\r\n\r\n<details><summary>$ pipenv --support</summary>\r\n\r\nPipenv version: `'2018.7.1'`\r\n\r\nPipenv location: `'c:\\\\python37\\\\lib\\\\site-packages\\\\pipenv'`\r\n\r\nPython location: `'c:\\\\python37\\\\python.exe'`\r\n\r\nOther Python installations in `PATH`:\r\n\r\n  - `3.7`: `C:\\Python37\\python.exe`\r\n\r\n  - `3.7.0`: `C:\\Python37\\python.exe`\r\n  - `3.7.0`: `C:\\Windows\\py.exe`\r\n\r\nPEP 508 Information:\r\n\r\n```\r\n{'implementation_name': 'cpython',\r\n 'implementation_version': '3.7.0',\r\n 'os_name': 'nt',\r\n 'platform_machine': 'AMD64',\r\n 'platform_python_implementation': 'CPython',\r\n 'platform_release': '10',\r\n 'platform_system': 'Windows',\r\n 'platform_version': '10.0.17134',\r\n 'python_full_version': '3.7.0',\r\n 'python_version': '3.7',\r\n 'sys_platform': 'win32'}\r\n```\n", "before_files": [{"content": "import collections\nimport contextlib\nimport os\nimport signal\nimport subprocess\nimport sys\n\nfrom ._compat import get_terminal_size, Path\nfrom .environments import PIPENV_SHELL_EXPLICIT, PIPENV_SHELL, PIPENV_EMULATOR\nfrom .utils import temp_environ\nfrom .vendor import shellingham\n\n\nShellDetectionFailure = shellingham.ShellDetectionFailure\n\n\ndef _build_info(value):\n    return (os.path.splitext(os.path.basename(value))[0], value)\n\n\ndef detect_info():\n    if PIPENV_SHELL_EXPLICIT:\n        return _build_info(PIPENV_SHELL_EXPLICIT)\n    try:\n        return shellingham.detect_shell()\n    except (shellingham.ShellDetectionFailure, TypeError):\n        if PIPENV_SHELL:\n            return _build_info(PIPENV_SHELL)\n    raise ShellDetectionFailure\n\n\ndef _get_activate_script(venv):\n    \"\"\"Returns the string to activate a virtualenv.\n\n    This is POSIX-only at the moment since the compat (pexpect-based) shell\n    does not work elsewhere anyway.\n    \"\"\"\n    # Suffix and source command for other shells.\n    # Support for fish shell.\n    if PIPENV_SHELL and \"fish\" in PIPENV_SHELL:\n        suffix = \".fish\"\n        command = \"source\"\n    # Support for csh shell.\n    elif PIPENV_SHELL and \"csh\" in PIPENV_SHELL:\n        suffix = \".csh\"\n        command = \"source\"\n    else:\n        suffix = \"\"\n        command = \".\"\n    # Escape any spaces located within the virtualenv path to allow\n    # for proper activation.\n    venv_location = str(venv).replace(\" \", r\"\\ \")\n    # The leading space can make history cleaner in some shells.\n    return \" {2} {0}/bin/activate{1}\".format(venv_location, suffix, command)\n\n\ndef _handover(cmd, args):\n    args = [cmd] + args\n    if os.name != \"nt\":\n        os.execvp(cmd, args)\n    else:\n        sys.exit(subprocess.call(args, shell=True, universal_newlines=True))\n\n\nclass Shell(object):\n    def __init__(self, cmd):\n        self.cmd = cmd\n        self.args = []\n\n    def __repr__(self):\n        return '{type}(cmd={cmd!r})'.format(\n            type=type(self).__name__,\n            cmd=self.cmd,\n        )\n\n    @contextlib.contextmanager\n    def inject_path(self, venv):\n        with temp_environ():\n            os.environ[\"PATH\"] = \"{0}{1}{2}\".format(\n                os.pathsep.join(str(p.parent) for p in _iter_python(venv)),\n                os.pathsep,\n                os.environ[\"PATH\"],\n            )\n            yield\n\n    def fork(self, venv, cwd, args):\n        # FIXME: This isn't necessarily the correct prompt. We should read the\n        # actual prompt by peeking into the activation script.\n        name = os.path.basename(venv)\n        os.environ[\"VIRTUAL_ENV\"] = str(venv)\n        if \"PROMPT\" in os.environ:\n            os.environ[\"PROMPT\"] = \"({0}) {1}\".format(name, os.environ[\"PROMPT\"])\n        if \"PS1\" in os.environ:\n            os.environ[\"PS1\"] = \"({0}) {1}\".format(name, os.environ[\"PS1\"])\n        with self.inject_path(venv):\n            os.chdir(cwd)\n            _handover(self.cmd, self.args + list(args))\n\n    def fork_compat(self, venv, cwd, args):\n        from .vendor import pexpect\n\n        # Grab current terminal dimensions to replace the hardcoded default\n        # dimensions of pexpect.\n        dims = get_terminal_size()\n        with temp_environ():\n            c = pexpect.spawn(self.cmd, [\"-i\"], dimensions=(dims.lines, dims.columns))\n        c.sendline(_get_activate_script(venv))\n        if args:\n            c.sendline(\" \".join(args))\n\n        # Handler for terminal resizing events\n        # Must be defined here to have the shell process in its context, since\n        # we can't pass it as an argument\n        def sigwinch_passthrough(sig, data):\n            dims = get_terminal_size()\n            c.setwinsize(dims.lines, dims.columns)\n\n        signal.signal(signal.SIGWINCH, sigwinch_passthrough)\n\n        # Interact with the new shell.\n        c.interact(escape_character=None)\n        c.close()\n        sys.exit(c.exitstatus)\n\n\nPOSSIBLE_ENV_PYTHON = [Path(\"bin\", \"python\"), Path(\"Scripts\", \"python.exe\")]\n\n\ndef _iter_python(venv):\n    for path in POSSIBLE_ENV_PYTHON:\n        full_path = Path(venv, path)\n        if full_path.is_file():\n            yield full_path\n\n\nclass Bash(Shell):\n    # The usual PATH injection technique does not work with Bash.\n    # https://github.com/berdario/pew/issues/58#issuecomment-102182346\n    @contextlib.contextmanager\n    def inject_path(self, venv):\n        from ._compat import NamedTemporaryFile\n\n        bashrc_path = Path.home().joinpath(\".bashrc\")\n        with NamedTemporaryFile(\"w+\") as rcfile:\n            if bashrc_path.is_file():\n                base_rc_src = 'source \"{0}\"\\n'.format(bashrc_path.as_posix())\n                rcfile.write(base_rc_src)\n\n            export_path = 'export PATH=\"{0}:$PATH\"\\n'.format(\n                \":\".join(python.parent.as_posix() for python in _iter_python(venv))\n            )\n            rcfile.write(export_path)\n            rcfile.flush()\n            self.args.extend([\"--rcfile\", rcfile.name])\n            yield\n\n\nclass CmderEmulatedShell(Shell):\n    def fork(self, venv, cwd, args):\n        if cwd:\n            os.environ[\"CMDER_START\"] = cwd\n        super(CmderEmulatedShell, self).fork(venv, cwd, args)\n\n\nclass CmderCommandPrompt(CmderEmulatedShell):\n    def fork(self, venv, cwd, args):\n        rc = os.path.expandvars(\"%CMDER_ROOT%\\\\vendor\\\\init.bat\")\n        if os.path.exists(rc):\n            self.args.extend([\"/k\", rc])\n        super(CmderCommandPrompt, self).fork(venv, cwd, args)\n\n\nclass CmderPowershell(Shell):\n    def fork(self, venv, cwd, args):\n        rc = os.path.expandvars(\"%CMDER_ROOT%\\\\vendor\\\\profile.ps1\")\n        if os.path.exists(rc):\n            self.args.extend(\n                [\n                    \"-ExecutionPolicy\",\n                    \"Bypass\",\n                    \"-NoLogo\",\n                    \"-NoProfile\",\n                    \"-NoExit\",\n                    \"-Command\",\n                    \"Invoke-Expression '. ''{0}'''\".format(rc),\n                ]\n            )\n        super(CmderPowershell, self).fork(venv, cwd, args)\n\n\n# Two dimensional dict. First is the shell type, second is the emulator type.\n# Example: SHELL_LOOKUP['powershell']['cmder'] => CmderPowershell.\nSHELL_LOOKUP = collections.defaultdict(\n    lambda: collections.defaultdict(lambda: Shell),\n    {\n        \"bash\": collections.defaultdict(lambda: Bash),\n        \"cmd\": collections.defaultdict(lambda: Shell, {\"cmder\": CmderCommandPrompt}),\n        \"powershell\": collections.defaultdict(\n            lambda: Shell, {\"cmder\": CmderPowershell}\n        ),\n        \"pwsh\": collections.defaultdict(lambda: Shell, {\"cmder\": CmderPowershell}),\n    },\n)\n\n\ndef _detect_emulator():\n    if os.environ.get(\"CMDER_ROOT\"):\n        return \"cmder\"\n    return \"\"\n\n\ndef choose_shell():\n    emulator = PIPENV_EMULATOR.lower() or _detect_emulator()\n    type_, command = detect_info()\n    return SHELL_LOOKUP[type_][emulator](command)\n", "path": "pipenv/shells.py"}], "after_files": [{"content": "import collections\nimport contextlib\nimport os\nimport signal\nimport subprocess\nimport sys\n\nfrom ._compat import get_terminal_size, Path\nfrom .environments import PIPENV_SHELL_EXPLICIT, PIPENV_SHELL, PIPENV_EMULATOR\nfrom .utils import temp_environ\nfrom .vendor import shellingham\n\n\nShellDetectionFailure = shellingham.ShellDetectionFailure\n\n\ndef _build_info(value):\n    return (os.path.splitext(os.path.basename(value))[0], value)\n\n\ndef detect_info():\n    if PIPENV_SHELL_EXPLICIT:\n        return _build_info(PIPENV_SHELL_EXPLICIT)\n    try:\n        return shellingham.detect_shell()\n    except (shellingham.ShellDetectionFailure, TypeError):\n        if PIPENV_SHELL:\n            return _build_info(PIPENV_SHELL)\n    raise ShellDetectionFailure\n\n\ndef _get_activate_script(venv):\n    \"\"\"Returns the string to activate a virtualenv.\n\n    This is POSIX-only at the moment since the compat (pexpect-based) shell\n    does not work elsewhere anyway.\n    \"\"\"\n    # Suffix and source command for other shells.\n    # Support for fish shell.\n    if PIPENV_SHELL and \"fish\" in PIPENV_SHELL:\n        suffix = \".fish\"\n        command = \"source\"\n    # Support for csh shell.\n    elif PIPENV_SHELL and \"csh\" in PIPENV_SHELL:\n        suffix = \".csh\"\n        command = \"source\"\n    else:\n        suffix = \"\"\n        command = \".\"\n    # Escape any spaces located within the virtualenv path to allow\n    # for proper activation.\n    venv_location = str(venv).replace(\" \", r\"\\ \")\n    # The leading space can make history cleaner in some shells.\n    return \" {2} {0}/bin/activate{1}\".format(venv_location, suffix, command)\n\n\ndef _handover(cmd, args):\n    args = [cmd] + args\n    if os.name != \"nt\":\n        os.execvp(cmd, args)\n    else:\n        sys.exit(subprocess.call(args, shell=True, universal_newlines=True))\n\n\nclass Shell(object):\n    def __init__(self, cmd):\n        self.cmd = cmd\n        self.args = []\n\n    def __repr__(self):\n        return '{type}(cmd={cmd!r})'.format(\n            type=type(self).__name__,\n            cmd=self.cmd,\n        )\n\n    @contextlib.contextmanager\n    def inject_path(self, venv):\n        with temp_environ():\n            os.environ[\"PATH\"] = \"{0}{1}{2}\".format(\n                os.pathsep.join(str(p.parent) for p in _iter_python(venv)),\n                os.pathsep,\n                os.environ[\"PATH\"],\n            )\n            yield\n\n    def fork(self, venv, cwd, args):\n        # FIXME: This isn't necessarily the correct prompt. We should read the\n        # actual prompt by peeking into the activation script.\n        name = os.path.basename(venv)\n        os.environ[\"VIRTUAL_ENV\"] = str(venv)\n        if \"PROMPT\" in os.environ:\n            os.environ[\"PROMPT\"] = \"({0}) {1}\".format(name, os.environ[\"PROMPT\"])\n        if \"PS1\" in os.environ:\n            os.environ[\"PS1\"] = \"({0}) {1}\".format(name, os.environ[\"PS1\"])\n        with self.inject_path(venv):\n            os.chdir(cwd)\n            _handover(self.cmd, self.args + list(args))\n\n    def fork_compat(self, venv, cwd, args):\n        from .vendor import pexpect\n\n        # Grab current terminal dimensions to replace the hardcoded default\n        # dimensions of pexpect.\n        dims = get_terminal_size()\n        with temp_environ():\n            c = pexpect.spawn(self.cmd, [\"-i\"], dimensions=(dims.lines, dims.columns))\n        c.sendline(_get_activate_script(venv))\n        if args:\n            c.sendline(\" \".join(args))\n\n        # Handler for terminal resizing events\n        # Must be defined here to have the shell process in its context, since\n        # we can't pass it as an argument\n        def sigwinch_passthrough(sig, data):\n            dims = get_terminal_size()\n            c.setwinsize(dims.lines, dims.columns)\n\n        signal.signal(signal.SIGWINCH, sigwinch_passthrough)\n\n        # Interact with the new shell.\n        c.interact(escape_character=None)\n        c.close()\n        sys.exit(c.exitstatus)\n\n\nPOSSIBLE_ENV_PYTHON = [Path(\"bin\", \"python\"), Path(\"Scripts\", \"python.exe\")]\n\n\ndef _iter_python(venv):\n    for path in POSSIBLE_ENV_PYTHON:\n        full_path = Path(venv, path)\n        if full_path.is_file():\n            yield full_path\n\n\nclass Bash(Shell):\n    def _format_path(self, python):\n        return python.parent.as_posix()\n\n    # The usual PATH injection technique does not work with Bash.\n    # https://github.com/berdario/pew/issues/58#issuecomment-102182346\n    @contextlib.contextmanager\n    def inject_path(self, venv):\n        from ._compat import NamedTemporaryFile\n\n        bashrc_path = Path.home().joinpath(\".bashrc\")\n        with NamedTemporaryFile(\"w+\") as rcfile:\n            if bashrc_path.is_file():\n                base_rc_src = 'source \"{0}\"\\n'.format(bashrc_path.as_posix())\n                rcfile.write(base_rc_src)\n\n            export_path = 'export PATH=\"{0}:$PATH\"\\n'.format(\":\".join(\n                self._format_path(python)\n                for python in _iter_python(venv)\n            ))\n            rcfile.write(export_path)\n            rcfile.flush()\n            self.args.extend([\"--rcfile\", rcfile.name])\n            yield\n\n\nclass MsysBash(Bash):\n    def _format_path(self, python):\n        s = super(MsysBash, self)._format_path(python)\n        if not python.drive:\n            return s\n        # Convert \"C:/something\" to \"/c/something\".\n        return '/{drive}{path}'.format(drive=s[0].lower(), path=s[2:])\n\n\nclass CmderEmulatedShell(Shell):\n    def fork(self, venv, cwd, args):\n        if cwd:\n            os.environ[\"CMDER_START\"] = cwd\n        super(CmderEmulatedShell, self).fork(venv, cwd, args)\n\n\nclass CmderCommandPrompt(CmderEmulatedShell):\n    def fork(self, venv, cwd, args):\n        rc = os.path.expandvars(\"%CMDER_ROOT%\\\\vendor\\\\init.bat\")\n        if os.path.exists(rc):\n            self.args.extend([\"/k\", rc])\n        super(CmderCommandPrompt, self).fork(venv, cwd, args)\n\n\nclass CmderPowershell(Shell):\n    def fork(self, venv, cwd, args):\n        rc = os.path.expandvars(\"%CMDER_ROOT%\\\\vendor\\\\profile.ps1\")\n        if os.path.exists(rc):\n            self.args.extend(\n                [\n                    \"-ExecutionPolicy\",\n                    \"Bypass\",\n                    \"-NoLogo\",\n                    \"-NoProfile\",\n                    \"-NoExit\",\n                    \"-Command\",\n                    \"Invoke-Expression '. ''{0}'''\".format(rc),\n                ]\n            )\n        super(CmderPowershell, self).fork(venv, cwd, args)\n\n\n# Two dimensional dict. First is the shell type, second is the emulator type.\n# Example: SHELL_LOOKUP['powershell']['cmder'] => CmderPowershell.\nSHELL_LOOKUP = collections.defaultdict(\n    lambda: collections.defaultdict(lambda: Shell),\n    {\n        \"bash\": collections.defaultdict(\n            lambda: Bash, {\"msys\": MsysBash},\n        ),\n        \"cmd\": collections.defaultdict(\n            lambda: Shell, {\"cmder\": CmderCommandPrompt},\n        ),\n        \"powershell\": collections.defaultdict(\n            lambda: Shell, {\"cmder\": CmderPowershell},\n        ),\n        \"pwsh\": collections.defaultdict(\n            lambda: Shell, {\"cmder\": CmderPowershell},\n        ),\n    },\n)\n\n\ndef _detect_emulator():\n    keys = []\n    if os.environ.get(\"CMDER_ROOT\"):\n        keys.append(\"cmder\")\n    if os.environ.get(\"MSYSTEM\"):\n        keys.append(\"msys\")\n    return \",\".join(keys)\n\n\ndef choose_shell():\n    emulator = PIPENV_EMULATOR.lower() or _detect_emulator()\n    type_, command = detect_info()\n    shell_types = SHELL_LOOKUP[type_]\n    for key in emulator.split(\",\"):\n        key = key.strip().lower()\n        if key in shell_types:\n            return shell_types[key](command)\n    return shell_types[\"\"](command)\n", "path": "pipenv/shells.py"}]}