From c797a2c7f5d2210ff32353834148dee89c6363d1 Mon Sep 17 00:00:00 2001 From: Daniel Biehl Date: Mon, 1 Jun 2026 00:57:15 +0200 Subject: [PATCH] fix: prepend PowerShell call operator when activating environments PowerShell parses a leading quoted string as an expression, so when the Hatch executable path contains a space (e.g. under "C:\Program Files"), the host-quoted activation command failed with a ParserError and the environment was not activated. Add a pwsh-specific shellActivation entry that prefixes the call operator `&`, matching how the built-in venv/poetry managers handle PowerShell. cmd/bash/zsh/fish keep using the shared entry, where `&` is neither needed nor valid. Fixes #196 --- src/hatch-env-manager.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/hatch-env-manager.ts b/src/hatch-env-manager.ts index e46c00c..dfd71c4 100644 --- a/src/hatch-env-manager.ts +++ b/src/hatch-env-manager.ts @@ -352,8 +352,13 @@ export class HatchEnvManager implements EnvironmentManager { const shellDeactivation: Map = new Map() - shellActivation.set('unknown', [ - { executable, args: [`--env=${name}`, 'shell'] }, + const args = ['--env', name, 'shell'] + shellActivation.set('unknown', [{ executable, args }]) + // PowerShell parses a leading quoted string as an expression, so a quoted + // executable path (e.g. under "C:\Program Files") must be invoked with the + // call operator `&`. A lone `&` is left unquoted by the host's quoting. + shellActivation.set('pwsh', [ + { executable: '&', args: [executable, ...args] }, ]) shellDeactivation.set('unknown', [{ executable: 'exit' }])