Skip to content

Instantly share code, notes, and snippets.

@ekardon
Last active November 18, 2022 07:59
Show Gist options
  • Save ekardon/fa04abbc7de02fac379581834ae59250 to your computer and use it in GitHub Desktop.
Save ekardon/fa04abbc7de02fac379581834ae59250 to your computer and use it in GitHub Desktop.
Fix PowerShell not starting with automatically in Terminal tab.
# Rename the file to: Microsoft.PowerShell_profile.ps1
# Replace it under default PS profile folder: C:\Users\<your_username>Documents\WindowsPowerShell
function Test-JetBrains-Product {
# The following enviromental variables are created with venv Pycharm 2021.3. I haven't tested any other product.
return (Test-Path Env:IDEA_INITIAL_DIRECTORY) -And (Test-Path Env:__INTELLIJ_COMMAND_HISTFILE__)
}
function Get-JetBrains-Product {
# $(Get-JetBrains-Product).Name
$product = Split-Path $Env:IDEA_INITIAL_DIRECTORY -Parent | Split-Path -Leaf
$name, $version = $product -split " "
return @{Name = $name; Version = $Version}
}
function Test-Virtual-Env {
return Test-Path Env:VIRTUAL_ENV
}
$venv_path = ".\venv"
$venv_activate_script = $venv_path + "\Scripts\Activate.ps1"
if ((Test-JetBrains-Product) -And
(Get-JetBrains-Product).Name -Eq "PyCharm" -And
(Test-Path $venv_activate_script)) {
# Apperently venv is active, but doesn't work correctly. So first we deactivate, then activate again.
if (Test-Virtual-Env) {
deactivate
}
& $venv_activate_script
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment