Skip to content

PowerShell hook: engine history keeps the wrapped line in an interactive session #51

Closed

Description

@NaNIsaac

In an interactive PowerShell session with the capture hook, the engine history (Get-History, history, r) keeps the wrapped form of every captured line, for example . __cdg { git status }, instead of the line as typed. #48 was meant to put the typed line back before the next prompt, and its unit test passes.

Cause: __cdg is dot-sourced, and at the prompt that means into the global scope. Its local $__cdgLine = $global:__cdgLine is therefore the global variable itself, and the cleanup in its finally (Remove-Variable ... __cdgLine ...) deletes it. __cdgRestoreHistory then finds no line and returns without restoring. The unit test calls __cdgRestoreHistory directly, without __cdg, so it does not see this.

To reproduce: start pwsh -NoProfile, dot-source src/codigest/shell/hook.ps1 with cdg on PATH, run echo a, then echo b, then (Get-History).CommandLine. It lists . __cdg { echo a } and . __cdg { echo b }.

Fix: give the local in __cdg a name of its own.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions