Skip to content

Commit

Permalink
Improve login shell heuristics
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Bates <kbates4@gmail.com>
  • Loading branch information
dlukes and kevin-bates committed Nov 18, 2020
1 parent 84f1012 commit cd56802
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions jupyter_server/terminal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys

import terminado
from ..utils import check_version
Expand All @@ -19,16 +20,18 @@ def initialize(webapp, root_dir, connection_url, settings):
default_shell = 'powershell.exe'
else:
default_shell = which('sh')
shell = settings.get('shell_command',
shell_override = settings.get('shell_command')
shell = (
[os.environ.get('SHELL') or default_shell]
if shell_override is None
else shell_override
)
# Enable login mode - to automatically source the /etc/profile
# script, but only for non-nested shells; for nested shells, it's
# superfluous and may even be harmful (e.g. on macOS, where login
# shells invoke /usr/libexec/path_helper to add entries from
# /etc/paths{,.d} to the PATH, reordering it in the process and
# potentially overriding virtualenvs and other PATH modifications)
if os.name != 'nt' and int(os.environ.get("SHLVL", 0)) < 1:
# When the notebook server is not running in a terminal (e.g. when
# it's launched by a JupyterHub spawner), it's likely that the user
# environment hasn't been fully set up. In that case, run a login
# shell to automatically source /etc/profile and the like, unless
# the user has specifically set a preferred shell command.
if os.name != 'nt' and shell_override is None and not sys.stdout.isatty():
shell.append('-l')
terminal_manager = webapp.settings['terminal_manager'] = NamedTermManager(
shell_command=shell,
Expand Down

0 comments on commit cd56802

Please sign in to comment.