Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _detect_shell():
shell = os.environ.get('SHELL', None)
if not shell:
if 'CMDER_ROOT' in os.environ:
shell = 'Cmder'
elif windows:
try:
_, shell = shellingham.detect_shell()
except shellingham.ShellDetectionFailure:
shell = os.environ.get('COMSPEC', 'cmd.exe')
else:
shell = 'sh'
return shell
def _shell_info(self) -> Tuple[str, Path]:
# detect by shellingham
try:
name, path = detect_shell()
except (ShellDetectionFailure, RuntimeError):
pass
else:
return name, Path(path)
# detect by env
for env in ('SHELL', 'COMSPEC'):
path = os.environ.get(env)
if path:
path = Path(path).resolve()
return path.stem, path
# try to find any known shell
for name in sorted(self.shells):
path = shutil.which(name)
if path is not None:
def get_auto_shell():
"""Returns the current shell"""
return shellingham.detect_shell()[0]
def get(cls): # type: () -> Shell
"""
Retrieve the current shell.
"""
if cls._shell is not None:
return cls._shell
try:
name, path = detect_shell(os.getpid())
except (RuntimeError, ShellDetectionFailure):
raise RuntimeError("Unable to detect the current shell.")
cls._shell = cls(name, path)
return cls._shell