Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shell detection #6230

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions pipenv/shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,34 @@ def _get_activate_script(cmd, venv):
does not work elsewhere anyway.
"""
# Suffix and source command for various shells.
if cmd.endswith("/sh", "/bash", "/zsh"):
suffix = ""
command = "."
elif cmd.endswith("/fish"):
command = "source"

if cmd.endswith("fish"):
suffix = ".fish"
command = "source"
elif cmd.endswith("/csh"):
elif cmd.endswith("csh"):
oz123 marked this conversation as resolved.
Show resolved Hide resolved
suffix = ".csh"
command = "source"
elif cmd.endswith("/xonsh"):
elif cmd.endswith("xonsh"):
suffix = ".xsh"
command = "source"
elif cmd.endswith("/nu"):
elif cmd.endswith("nu"):
suffix = ".nu"
command = "overlay use"
elif cmd.endswith(("pwsh", "powershell")):
suffix = ".ps1"
command = "."
elif cmd.endswith(("sh", "bash", "zsh")):
suffix = ""
else:
raise ValueError(f"unknown shell {cmd}")
sys.exit(f"unknown shell {cmd}")

# Escape any special characters located within the virtualenv path to allow
# for proper activation.
venv_location = re.sub(r"([ &$()\[\]])", r"\\\1", str(venv))

if suffix == "nu":
return f"overlay use {venv_location}"
elif suffix == ".ps1":
return f". {venv_location}\\Scripts\\Activate.{suffix}"

# The leading space can make history cleaner in some shells.
return f" {command} {venv_location}/bin/activate{suffix}"

Expand Down
Loading