Skip to content

feat(executiontime): support execution time measurement in terminals with pwsh#7381

Open
heaths wants to merge 1 commit intoJanDeDobbeleer:mainfrom
heaths:issue7377
Open

feat(executiontime): support execution time measurement in terminals with pwsh#7381
heaths wants to merge 1 commit intoJanDeDobbeleer:mainfrom
heaths:issue7377

Conversation

@heaths
Copy link
Copy Markdown
Contributor

@heaths heaths commented Mar 11, 2026

Resolves #7377 by writing the FTCS_COMMAND_EXECUTED (OSC 133;C) VT sequence that some terminals support to measure execution time.

Follows similar pattern as bash support.

Copilot AI review requested due to automatic review settings March 11, 2026 17:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds PowerShell (pwsh) shell-integration support for emitting the FTCS_COMMAND_EXECUTED (OSC 133;C) VT sequence so terminals (e.g., Ghostty) can correctly measure command execution time, aligning behavior with existing bash/zsh/fish patterns.

Changes:

  • Hooks PSConsoleHostReadLine to emit OSC 133;C at the start of command execution.
  • Extracts OSC 133;C emission into a reusable Write-CommandExecuted helper and reuses it in the Enter key handler.
  • Restores the original PSConsoleHostReadLine function during module cleanup.

Resolves JanDeDobbeleer#7377 by writing the FTCS_COMMAND_EXECUTED (OSC 133;C) VT sequence that some terminals
support to measure execution time.

Follows similar pattern as bash support.

Replaces streaming-only write of OSC 133;C added in JanDeDobbeleer#3842.
@heaths
Copy link
Copy Markdown
Contributor Author

heaths commented Mar 14, 2026

@JanDeDobbeleer I could update this PR to include ;cmdline_url=<URI-encoded command line> as well, which is part of the OSC 133 protocol. Seems not many terminals currently use this. Some, like Ghostty, do, though they currently have a bug that will be likely fixed for their next release (1.4): ghostty-org/ghostty#9134

Or, if you're open to that change, would you prefer I make it in a separate PR after Ghostty is updated so I can accurately test it? For now, I'm working around it with a change that might be worth considering anyway for other terminals: https://github.com/heaths/profile/blob/8a34c07703944fa315a8b2c4e7dcf780fe836e50/Microsoft.PowerShell_profile.ps1#L42-L49

$line = _omp_host_readline
if (![String]::IsNullOrWhiteSpace($line)) {
    # Work around https://github.com/ghostty-org/ghostty/discussions/11477
    Write-Host -NoNewline "`e]2;$($line -replace '\p{Cc}', '')`a"
    Write-Host -NoNewline "`e]133;C;cmdline_url=$([Uri]::EscapeUriString($line))`a"
}

$line

That could be considered part of shell_integration or, perhaps, a specific feature. I'm not aware nor can I find any existing configuration beyond shell_integration that would accommodate that, but it is pretty handy when you have several terminal windows or tabs and want to see what long-running commands they are running.

@heaths heaths changed the title feat: support execution time measurement in terminals with pwsh feat(executiontime): support execution time measurement in terminals with pwsh Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OSC 133 shell integration is missing start of command execution

3 participants