annahosanna

Results 16 comments of annahosanna

Updating GitPrompt.ps1 to set GitPromptSettings.Debug to $true had no effect (prompt was still "PS>" )

Your second suggestion worked: PS>cd .\myrepo PS>$GitPromptSettings.DefaultPromptPath = '$pwd' C:\Users\me\Documents\GitHub\myrepo [master ≡]>

PS>$(Get-PromptPath) C:\Users\me\Documents\GitHub\myrepo PS> PS>$GitPromptSettings.DefaultPromptPath = $(Get-PromptPath) C:\Users\me\Documents\GitHub\myrepo [master ≡]>

Seems like it is using the literal value "$(Get-PromptPath)" rather than the result from evaluating that function. PS>write-host $Global:GitPromptSettings.DefaultPromptPath $(Get-PromptPath) PS>$GitPromptSettings.DefaultPromptPath = $(Get-PromptPath) C:\Users\me\Documents\GitHub\myrepo [master ≡]> write-host $Global:GitPromptSettings.DefaultPromptPath C:\Users\me\Documents\GitHub\myrepo

I think it is from GitPrompt.ps1. (in this version). DefaultPromptPath should be using quotes not ticks. DefaultPromptPath = '$(Get-PromptPath)' should be: DefaultPromptPath = "$(Get-PromptPath)"

I'm guessing it is because $ExecutionContext.SessionState is not defined/null when expanded from a string, but defined when it is called as part of a script/script block. This does not work...

But this works: ``` C:\Users\me\Documents\GitHub\myrepo [master ≡]> $ExecutionContext.SessionState.InvokeCommand.InvokeScript($ExecutionContext.SessionState.InvokeCommand.NewScriptBlock('$($ExecutionContext.SessionState.Path.CurrentLocation.Path)')) ``` This works too: ``` PS>$Global:GitPromptSettings.DefaultPromptPath='$(Get-PromptPath)' PS>$ExecutionContext.SessionState.InvokeCommand.InvokeScript($ExecutionContext.SessionState.InvokeCommand.NewScriptBlock($Global:GitPromptSettings.DefaultPromptPath)) C:\Users\me\Documents\GitHub\myrepo ``` This works in the GitPromptScritpBlock replacing: ``` $currentPath = $ExecutionContext.SessionState.InvokeCommand.ExpandString($GitPromptSettings.DefaultPromptPath) ``` With: ```...

It works with single quotes, and performs dynamic expansion. It creates a script block from the text in single quotes, and then evaluates the script block. However, because this is...

@rkeithhill Sorry I must have miscommunicated something. 1) I no longer get the nullref using $ExecutionContext.SessionState.InvokeCommand.InvokeScript instead of $ExecutionContext.SessionState.InvokeCommand.ExpandString. 2) I understood that you were using `'` to control when...

@dahlbyk No ``` PS>$ExecutionContext.SessionState.InvokeCommand.ExpandString('$(Get-Location)') Object reference not set to an instance of an object. + CategoryInfo : OperationStopped: (:) [], NullReferenceException + FullyQualifiedErrorId : System.NullReferenceException ```