I'm seeing the following message when my $profile gets executed:
Rename-Item : Cannot rename because item at 'Function:\Prompt' does not exist.
At C:\Users\myuser\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:66 char:1
+ Rename-Item Function:\Prompt PoshGitPrompt -Force
here's what the relevant line looks like:
. 'C:\tools\poshgit\dahlbyk-posh-git-464601f\profile.example.ps1'
Rename-Item Function:\Prompt PoshGitPrompt -Force
function Prompt() {if(Test-Path Function:\PrePoshGitPrompt){++$global:poshScope; New-Item function:\script:Write-host -value "param([object] `$object, `$backgroundColor, `$foregroundColor, [switch] `$nonewline) " -Force | Out-Null;$private:p = PrePoshGitPrompt; if(--$global:poshScope -eq 0) {Remove-Item function:\Write-Host -Force}}PoshGitPrompt}
Are you using latest bits from this repo or the latest poshgit from Chocolatey?
If you are using the latest bits from this repo (the not yet released 0.7.0) you can comment out the these lines e.g.:
# Rename-Item Function:\Prompt PoshGitPrompt -Force
# function Prompt() {if(Test-Path Function:\PrePoshGitPrompt){++$global:poshScope; New-Item function:\script:Write-host -value "param([object] `$object, `$backgroundColor, `$foregroundColor, [switch] `$nonewline) " -Force | Out-Null;$private:p = PrePoshGitPrompt; if(--$global:poshScope -eq 0) {Remove-Item function:\Write-Host -Force}}PoshGitPrompt}
Even if you're not using the latest repo bits, you might try commenting out the lines above.
BTW which version of PowerShell are you using (check with $PSVersionTable.PSVersion)?
Are you using latest bits from this repo or the latest poshgit from Chocolatey?
C:\tools\poshgit\dahlbyk-posh-git-464601f SHA is the merge of #349: https://github.com/dahlbyk/posh-git/commits/464601f. For the record, this is why we need to pin the Chocolatey package to the tagged version rather than master. 馃槖
I would not expect loading profile.example.ps1 to result in Function:\Prompt being missing. It looks like we might be getting confused if Function:Prompt doesn't exist when the module is imported?
For reference, this is what a Chocolatey-installed $PROFILE looks like:
if(Test-Path Function:\Prompt) {Rename-Item Function:\Prompt PrePoshGitPrompt -Force}
# Load posh-git example profile
. 'C:\tools\poshgit\dahlbyk-posh-git-464601f\profile.example.ps1'
Rename-Item Function:\Prompt PoshGitPrompt -Force
function Prompt() {if(Test-Path Function:\PrePoshGitPrompt){++$global:poshScope; New-Item function:\script:Write-host -value "param([object] `$object, `$backgroundColor, `$foregroundColor, [switch] `$nonewline) " -Force | Out-Null;$private:p = PrePoshGitPrompt; if(--$global:poshScope -eq 0) {Remove-Item function:\Write-Host -Force}}PoshGitPrompt}
I'd love for all of this to be replaced in 1.0 with Import-Module posh-git.
Yeah, the code to set prompt is definitely broken if prompt doesn't exist: #357
Thanks for the bug report, @ewgoforth!
I'm using the following powershell version:
PS>$PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 1 14393 187
PS>
I am using the latest from chocolatey as of yesterday. If I comment out everything it's normal, but I don't get the posh-git functionality:
#if(Test-Path Function:\Prompt) {Rename-Item Function:\Prompt PrePoshGitPrompt -Force}
# Load posh-git example profile. 'C:\tools\poshgit\dahlbyk-posh-git-464601f\profile.example.ps1'
#Rename-Item Function:\Prompt PoshGitPrompt -Force
#function Prompt() {if(Test-Path Function:\PrePoshGitPrompt){++$global:poshScope; New-Item function:\script:Write-host -value "param([object] `$object, `$backgroundColor, `$foregroundColor, [switch] `$nonewline) " -Force | Out-Null;$private:p = PrePoshGitPrompt; if(--$global:poshScope -eq 0) {Remove-Item function:\Write-Host -Force}}PoshGitPrompt}
I would uncomment the second line (by which I mean add a newline after "example profile" and before the .) and delete the other three - they shouldn't be necessary, and will be removed when we move to 1.0.
I did that like so:
#if(Test-Path Function:\Prompt) {Rename-Item Function:\Prompt PrePoshGitPrompt -Force}
# Load posh-git example profile
. 'C:\tools\poshgit\dahlbyk-posh-git-464601f\profile.example.ps1'
#Rename-Item Function:\Prompt PoshGitPrompt -Force
#function Prompt() {if(Test-Path Function:\PrePoshGitPrompt){++$global:poshScope; New-Item function:\script:Write-host -value "param([object] `$object, `$backgroundColor, `$foregroundColor, [switch] `$nonewline) " -Force | Out-Null;$private:p = PrePoshGitPrompt; if(--$global:poshScope -eq 0) {Remove-Item function:\Write-Host -Force}}PoshGitPrompt}
and I seem to have the full poshgit functionality.
So as an action item for this issue, is there something in the Chocolatey package that needs to be tweaked for 0.7.0? Also, just removing those lines probably wouldn't help someone who has a previously (Chocolatey) installed version of poshgit. What should we do there?
@ewgoforth if you don't mind, could you do a choco install poshgit --force to get latest and verify that the error doesn't return if you uncomment all those lines?
So as an action item for this issue, is there something in the Chocolatey package that needs to be tweaked for 0.7.0?
I believe #357 is technically sufficient, but we have #239 marked for 0.7 so: #358.
Most helpful comment
I did that like so:
and I seem to have the full poshgit functionality.