Skip to content

Commit 88e56fe

Browse files
committed
Improve venv shell activation in fish shell
Instead of mimicking a user typing the command we use fish's builtin `--init-command` option.
1 parent 2963d74 commit 88e56fe

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/poetry/utils/shell.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ def activate(self, env: VirtualEnv) -> int | None:
106106
cmd = f"{self._get_source_command()} {shlex.quote(str(activate_path))}"
107107

108108
with env.temp_environ():
109-
args = ["-e", cmd] if self._name == "nu" else ["-i"]
109+
if self._name == "nu":
110+
args = ["-e", cmd]
111+
elif self._name == "fish":
112+
args = ["-i", "--init-command", cmd]
113+
else:
114+
args = ["-i"]
110115

111116
c = pexpect.spawn(
112117
self._path, args, dimensions=(terminal.lines, terminal.columns)
@@ -120,14 +125,11 @@ def activate(self, env: VirtualEnv) -> int | None:
120125
c.sendline(f"emulate bash -c '. {shlex.quote(str(activate_path))}'")
121126
elif self._name == "xonsh":
122127
c.sendline(f"vox activate {shlex.quote(str(env.path))}")
123-
elif self._name == "nu":
124-
# If this is nu, we don't want to send the activation command to the
128+
elif self._name in ["nu", "fish"]:
129+
# If this is nu or fish, we don't want to send the activation command to the
125130
# command line since we already ran it via the shell's invocation.
126131
pass
127132
else:
128-
if self._name in ["fish"]:
129-
# Under fish, "\r" should be sent explicitly
130-
cmd += "\r"
131133
c.sendline(cmd)
132134

133135
def resize(sig: Any, data: Any) -> None:

0 commit comments

Comments
 (0)