Skip to content

Coexistence of posh-git and miniconda. Can't suppress warning: "If your prompt function uses any posh-git commands, it will cause posh-git to be re-imported every time your prompt function is invoked." #991

@futuremotiondev

Description

@futuremotiondev

I have miniconda3 and posh-git installed. I've configured my profile to load the conda hook on demand since it impacts loading time of my shell (adds about ~2 seconds compared to an almost instant startup).

Relevant profile bits:

Import-Module posh-git -Force
$GitPromptSettings.DefaultPromptPrefix.Text                  = '$(Get-Date -f "yyyy-MM-dd HH:mm") '
$GitPromptSettings.DefaultPromptPrefix.ForegroundColor       = [ConsoleColor]::DarkGray
$GitPromptSettings.DefaultPromptPath.ForegroundColor         = [ConsoleColor]::Gray
$GitPromptSettings.BeforeStatus.ForegroundColor              = [ConsoleColor]::DarkGray
$GitPromptSettings.DelimStatus.ForegroundColor               = [ConsoleColor]::DarkGray
$GitPromptSettings.AfterStatus.ForegroundColor               = [ConsoleColor]::DarkGray
$GitPromptSettings.BranchColor.ForegroundColor               = [ConsoleColor]::Cyan
$GitPromptSettings.WorkingColor.ForegroundColor              = [ConsoleColor]::Red
$GitPromptSettings.LocalWorkingStatusSymbol.ForegroundColor  = [ConsoleColor]::Red
$GitPromptSettings.BranchBehindStatusSymbol.ForegroundColor  = [ConsoleColor]::Red
$GitPromptSettings.IndexColor.ForegroundColor                = [ConsoleColor]::Green

Set-Alias -Name 'condahook' -Value EnableConda
Set-Alias -Name 'exitconda' -Value DisableConda

function EnableConda {
    If (Test-Path "C:\Python\miniconda3\Scripts\conda.exe") {
        (& "C:\Python\miniconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | ?{$_} | iex
    }
}

function DisableConda {
    Remove-Module -FullyQualifiedName "$Env:_CONDA_ROOT\shell\condabin\Conda.psm1" -ErrorAction Ignore | Out-Null
    # I have to re-import posh-git here because for some unknown reason it fails to work after
    # removing the Conda.psm1 module.
    Import-Module posh-git -Force -WarningAction Ignore | Out-Null
    $GitPromptSettings.DefaultPromptPrefix.Text                  = '$(Get-Date -f "yyyy-MM-dd HH:mm") '
    $GitPromptSettings.DefaultPromptPrefix.ForegroundColor       = [ConsoleColor]::DarkGray
    $GitPromptSettings.DefaultPromptPath.ForegroundColor         = [ConsoleColor]::Gray
    $GitPromptSettings.BeforeStatus.ForegroundColor              = [ConsoleColor]::DarkGray
    $GitPromptSettings.DelimStatus.ForegroundColor               = [ConsoleColor]::DarkGray
    $GitPromptSettings.AfterStatus.ForegroundColor               = [ConsoleColor]::DarkGray
    $GitPromptSettings.BranchColor.ForegroundColor               = [ConsoleColor]::Cyan
    $GitPromptSettings.WorkingColor.ForegroundColor              = [ConsoleColor]::Red
    $GitPromptSettings.LocalWorkingStatusSymbol.ForegroundColor  = [ConsoleColor]::Red
    $GitPromptSettings.BranchBehindStatusSymbol.ForegroundColor  = [ConsoleColor]::Red
    $GitPromptSettings.IndexColor.ForegroundColor                = [ConsoleColor]::Green
}

The condahook alias works as expected and activates the conda base environment, and I can switch envs, etc. The exitconda alias, however, emits a warning:

WARNING: If your prompt function uses any posh-git commands, it will cause posh-git to be re-imported every time your prompt function is invoked.

As well as a powershell "suggestion":

Suggestion [4,General]: The most similar commands are:

Despite the warning and suggestion text, things seem to work as expected.

  1. Why is this warning being generated?
  2. How can I suppress this warning?
  3. Why is powershell offering a suggestion as if I entered an unknown or unrecognized command?
  4. How can I suppress the powershell "suggestion"? (I tried Disable-ExperimentalFeature PSFeedbackProvider and it did nothing)
  5. Is there a tried and true method of getting both miniconda and posh-git to co-exist without issue?
  6. I'd like to avoid loading conda automatically since it impacts my console startup time so drastically.

Any help would be greatly appreciated. This issue is frustrating the heck out of me right now.

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