Skip to content

Commit 518b699

Browse files
authored
utils: fallback to env var when detecting shell (#2147)
Resolves: #2115
1 parent f76ceee commit 518b699

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

poetry/utils/shell.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from shellingham import detect_shell
1010

1111
from ._compat import WINDOWS
12+
from ._compat import Path
1213
from .env import VirtualEnv
1314

1415

@@ -42,7 +43,17 @@ def get(cls): # type: () -> Shell
4243
try:
4344
name, path = detect_shell(os.getpid())
4445
except (RuntimeError, ShellDetectionFailure):
45-
raise RuntimeError("Unable to detect the current shell.")
46+
shell = None
47+
48+
if os.name == "posix":
49+
shell = os.environ.get("SHELL")
50+
elif os.name == "nt":
51+
shell = os.environ.get("COMSPEC")
52+
53+
if not shell:
54+
raise RuntimeError("Unable to detect the current shell.")
55+
56+
name, path = Path(shell).stem, shell
4657

4758
cls._shell = cls(name, path)
4859

0 commit comments

Comments
 (0)