Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding to Prompt conflicts with other bindings #8

Open
boriscallens opened this issue Dec 26, 2024 · 0 comments
Open

Binding to Prompt conflicts with other bindings #8

boriscallens opened this issue Dec 26, 2024 · 0 comments

Comments

@boriscallens
Copy link

boriscallens commented Dec 26, 2024

The readme suggests hooking every prompt to the update-navigationhistory function with the below piece of code.
This overrides any other hook that was already added (eg Oh-My-Posh) and on my mashine only appeared to work in elevated mode. Depending on the order of execution one hook overrides the next.

After some digging I landed on a wrapping Set-Location instead.
This appears to be conflict free and more focused on the relevant command instead of every command.
Still feels a little dirty so open for feedback.

Before:

function Prompt {
	Update-NavigationHistory $pwd.Path
}

After:

# Save the existing Set-Location cmdlet to a variable
# Then redefine Set-Location to include Update-NavigationHistory
$originalSetLocation = Get-Command Set-Location
function Set-Location {
  param (
      [string]$Path,
      [switch]$PassThru,
      [switch]$UseTransaction,
      [pscredential]$Credential
  )
  & $originalSetLocation @PSBoundParameters
  Update-NavigationHistory (Get-Location).Path
}
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

No branches or pull requests

1 participant