Skip to content

Commit 679683c

Browse files
authored
Merge pull request #343 from kevin-bates/port-5565-5588
Port Notebook PRs 5565 and 5588 - terminal shell heuristics
2 parents bbf01ba + 66962b5 commit 679683c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

jupyter_server/terminal/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23

34
import terminado
45
from ..utils import check_version
@@ -19,11 +20,18 @@ def initialize(webapp, root_dir, connection_url, settings):
1920
default_shell = 'powershell.exe'
2021
else:
2122
default_shell = which('sh')
22-
shell = settings.get('shell_command',
23+
shell_override = settings.get('shell_command')
24+
shell = (
2325
[os.environ.get('SHELL') or default_shell]
26+
if shell_override is None
27+
else shell_override
2428
)
25-
# Enable login mode - to automatically source the /etc/profile script
26-
if os.name != 'nt':
29+
# When the notebook server is not running in a terminal (e.g. when
30+
# it's launched by a JupyterHub spawner), it's likely that the user
31+
# environment hasn't been fully set up. In that case, run a login
32+
# shell to automatically source /etc/profile and the like, unless
33+
# the user has specifically set a preferred shell command.
34+
if os.name != 'nt' and shell_override is None and not sys.stdout.isatty():
2735
shell.append('-l')
2836
terminal_manager = webapp.settings['terminal_manager'] = NamedTermManager(
2937
shell_command=shell,

0 commit comments

Comments
 (0)