Skip to content

Shell escape: support PowerShell scripts (.ps1) on Windows #568

Description

@stalep

Summary

The shell escape feature (#566) uses cmd /c on Windows, which correctly handles .bat and .cmd files. However, PowerShell scripts (.ps1) do not work with cmd /c — they require powershell -File or pwsh -File.

Current behavior

[myshell]$ !deploy.ps1
'deploy.ps1' is not recognized as an internal or external command

Expected behavior

[myshell]$ !deploy.ps1
Deploying to production...
Done.

Proposed approach

In executeNativeCommand(), detect the file extension of the first token:

  • .bat / .cmd / no extension / built-in commands -> cmd /c command (current behavior)
  • .ps1 -> powershell -File script.ps1 args... or pwsh -File script.ps1 args...

Auto-detect whether pwsh (PowerShell Core, cross-platform) or powershell (Windows PowerShell) is available.

Alternative

Instead of auto-detecting, add a setting for the shell command:

SettingsBuilder.builder()
    .shellEscapeCommand("pwsh", "-Command")  // override default sh/cmd

This would also support using bash on Windows (via WSL or Git Bash).

Context

Follow-up to #566 (shell escape via ! prefix).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions