Skip to content

Instantly share code, notes, and snippets.

@ochen1
Created January 9, 2025 08:00
Show Gist options
  • Save ochen1/35e9b521c59cdb5b4a2f2f8f5045a94a to your computer and use it in GitHub Desktop.
Save ochen1/35e9b521c59cdb5b4a2f2f8f5045a94a to your computer and use it in GitHub Desktop.
Lazy load conda in PowerShell (drop-in replacement)
# ~/Documents/WindowsPowerShell/profile.ps1
function Conda {
# Check if the initialization has already been performed
if (-not $global:CondaInitialized) {
# Perform the initialization
if (Test-Path "C:\ProgramData\miniconda3\Scripts\conda.exe") {
(& "C:\ProgramData\miniconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | ?{$_} | Invoke-Expression
} else {
Write-Error "Conda executable not found at the specified path."
return
}
# Set the flag to indicate initialization is complete
$global:CondaInitialized = $true
}
# Pass the original arguments to the conda command
& conda @args
}
# Ensure the function is loaded in the current session
#Set-Alias conda Conda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment