diff --git a/src/shell/scripts/omp.bash b/src/shell/scripts/omp.bash index 3303b139c6ce..44e6151342a3 100644 --- a/src/shell/scripts/omp.bash +++ b/src/shell/scripts/omp.bash @@ -6,6 +6,10 @@ export POSH_SESSION_ID=::SESSION_ID:: export CONDA_PROMPT_MODIFIER=false export OSTYPE=$OSTYPE +# disable all known python virtual environment prompts +export VIRTUAL_ENV_DISABLE_PROMPT=1 +export PYENV_VIRTUALENV_DISABLE_PROMPT=1 + # global variables _omp_start_time='' _omp_stack_count=0 diff --git a/src/shell/scripts/omp.elv b/src/shell/scripts/omp.elv index 6af727932e26..ff6f29a46015 100644 --- a/src/shell/scripts/omp.elv +++ b/src/shell/scripts/omp.elv @@ -4,6 +4,10 @@ set-env POSH_SHELL elvish set-env POSH_SHELL_VERSION $version set-env POWERLINE_COMMAND oh-my-posh +# disable all known python virtual environment prompts +set-env VIRTUAL_ENV_DISABLE_PROMPT 1 +set-env PYENV_VIRTUALENV_DISABLE_PROMPT 1 + var _omp_executable = (external ::OMP::) var _omp_status = 0 var _omp_no_status = 1 diff --git a/src/shell/scripts/omp.fish b/src/shell/scripts/omp.fish index 07eb4f522065..a7a2e5c96f6a 100644 --- a/src/shell/scripts/omp.fish +++ b/src/shell/scripts/omp.fish @@ -13,6 +13,10 @@ set --global _omp_ftcs_marks 0 set --global _omp_transient_prompt 0 set --global _omp_prompt_mark 0 +# disable all known python virtual environment prompts +set --global VIRTUAL_ENV_DISABLE_PROMPT 1 +set --global PYENV_VIRTUALENV_DISABLE_PROMPT 1 + # We use this to avoid unnecessary CLI calls for prompt repaint. set --global _omp_new_prompt 1 diff --git a/src/shell/scripts/omp.lua b/src/shell/scripts/omp.lua index 7711fcb13931..1e6d1f543bab 100644 --- a/src/shell/scripts/omp.lua +++ b/src/shell/scripts/omp.lua @@ -6,6 +6,10 @@ os.setenv('POSH_SESSION_ID', '::SESSION_ID::') os.setenv('POSH_SHELL', 'cmd') +-- disable all known python virtual environment prompts +os.setenv('VIRTUAL_ENV_DISABLE_PROMPT', '1') +os.setenv('PYENV_VIRTUALENV_DISABLE_PROMPT', '1') + -- Helper functions local function get_priority_number(name, default) diff --git a/src/shell/scripts/omp.nu b/src/shell/scripts/omp.nu index c64d9420e0bb..33bb8d8eb360 100644 --- a/src/shell/scripts/omp.nu +++ b/src/shell/scripts/omp.nu @@ -10,6 +10,10 @@ $env.POSH_SESSION_ID = (echo ::SESSION_ID::) $env.POSH_SHELL = "nu" $env.POSH_SHELL_VERSION = (version | get version) +# disable all known python virtual environment prompts +$env.VIRTUAL_ENV_DISABLE_PROMPT = 1 +$env.PYENV_VIRTUALENV_DISABLE_PROMPT = 1 + let _omp_executable: string = (echo ::OMP::) # PROMPTS diff --git a/src/shell/scripts/omp.ps1 b/src/shell/scripts/omp.ps1 index 6db4f4031f35..51dfd668d750 100644 --- a/src/shell/scripts/omp.ps1 +++ b/src/shell/scripts/omp.ps1 @@ -3,6 +3,10 @@ if ($null -ne (Get-Module -Name "oh-my-posh-core")) { Remove-Module -Name "oh-my-posh-core" -Force } +# disable all known python virtual environment prompts +$env:VIRTUAL_ENV_DISABLE_PROMPT = 1 +$env:PYENV_VIRTUALENV_DISABLE_PROMPT = 1 + # Helper functions which need to be defined before the module is loaded # See https://github.com/JanDeDobbeleer/oh-my-posh/discussions/2300 function global:Get-PoshStackCount { @@ -66,7 +70,8 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock { # ref-1: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.argumentlist?view=net-6.0 # ref-2: https://docs.microsoft.com/en-us/powershell/scripting/whats-new/differences-from-windows-powershell?view=powershell-7.2#net-framework-vs-net-core $Arguments | ForEach-Object -Process { $StartInfo.ArgumentList.Add($_) } - } else { + } + else { # escape arguments manually in lower versions, refer to https://docs.microsoft.com/en-us/previous-versions/17w5ykft(v=vs.85) $escapedArgs = $Arguments | ForEach-Object { # escape N consecutive backslash(es), which are followed by a double quote, to 2N consecutive ones @@ -154,7 +159,8 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock { $script:TransientPrompt = $true [Console]::OutputEncoding = [Text.Encoding]::UTF8 [Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt() - } finally { + } + finally { [Console]::OutputEncoding = $previousOutputEncoding } } @@ -184,14 +190,16 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock { if ($global:_ompAzure) { try { $env:POSH_AZURE_SUBSCRIPTION = Get-AzContext | ConvertTo-Json - } catch {} + } + catch {} } if ($global:_ompPoshGit) { try { $global:GitStatus = Get-GitStatus $env:POSH_GIT_STATUS = $global:GitStatus | ConvertTo-Json - } catch {} + } + catch {} } } @@ -216,7 +224,8 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock { $invocationInfo = try { # retrieve info of the most recent error $global:Error[0] | Where-Object { $_ -ne $null } | Select-Object -ExpandProperty InvocationInfo - } catch { $null } + } + catch { $null } # check if the last command caused the last error if ($null -ne $invocationInfo -and $lastHistory.CommandLine -eq $invocationInfo.Line) { @@ -260,7 +269,8 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock { if ($global:NVS_ORIGINAL_LASTEXECUTIONSTATUS -is [bool]) { # make it compatible with NVS auto-switching, if enabled $script:OriginalLastExecutionStatus = $global:NVS_ORIGINAL_LASTEXECUTIONSTATUS - } else { + } + else { $script:OriginalLastExecutionStatus = $? } # store the orignal last exit code @@ -346,7 +356,8 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock { # Workaround to prevent the text after cursor from disappearing when the tooltip is printed. [Microsoft.PowerShell.PSConsoleReadLine]::Insert(' ') [Microsoft.PowerShell.PSConsoleReadLine]::Undo() - } finally {} + } + finally {} } } @@ -364,7 +375,8 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock { $script:TooltipCommand = '' Set-TransientPrompt } - } finally { + } + finally { [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() if ($global:_ompFTCSMarks -and $executingCommand) { # Write FTCS_COMMAND_EXECUTED after accepting the input - it should still happen before execution @@ -382,7 +394,8 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock { $script:TooltipCommand = '' Set-TransientPrompt } - } finally { + } + finally { [Microsoft.PowerShell.PSConsoleReadLine]::CopyOrCancelLine() } } @@ -479,7 +492,8 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock { $themes = Get-ChildItem -Path "$Path/*" -Include '*.omp.json' | Sort-Object Name if ($List -eq $true) { $themes | Select-Object @{ Name = 'hyperlink'; Expression = { Get-FileHyperlink -Uri $_.FullName } } | Format-Table -HideTableHeaders - } else { + } + else { $nonFSWD = Get-NonFSWD $stackCount = Get-PoshStackCount $terminalWidth = Get-TerminalWidth diff --git a/src/shell/scripts/omp.tcsh b/src/shell/scripts/omp.tcsh index a25328d93a5d..6e7f403b61a8 100644 --- a/src/shell/scripts/omp.tcsh +++ b/src/shell/scripts/omp.tcsh @@ -5,6 +5,10 @@ setenv POSH_SHELL_VERSION "$tcsh"; setenv POSH_SESSION_ID ::SESSION_ID::; setenv OSTYPE "$OSTYPE"; +# disable all known python virtual environment prompts +setenv VIRTUAL_ENV_DISABLE_PROMPT 1; +setenv PYENV_VIRTUALENV_DISABLE_PROMPT 1; + if ( ! $?_omp_enabled ) alias precmd ' set _omp_status = $status; set _omp_execution_time = -1; diff --git a/src/shell/scripts/omp.xsh b/src/shell/scripts/omp.xsh index aa06eef8dce9..80fe305cf05c 100644 --- a/src/shell/scripts/omp.xsh +++ b/src/shell/scripts/omp.xsh @@ -4,6 +4,10 @@ $POSH_SESSION_ID = ::SESSION_ID:: $POSH_SHELL = "xonsh" $POSH_SHELL_VERSION = $XONSH_VERSION +# disable all known python virtual environment prompts +$VIRTUAL_ENV_DISABLE_PROMPT = 1 +$PYENV_VIRTUALENV_DISABLE_PROMPT = 1 + _omp_executable = ::OMP:: _omp_history_length = 0 diff --git a/src/shell/scripts/omp.zsh b/src/shell/scripts/omp.zsh index 453af1eb7baa..187399696c6c 100644 --- a/src/shell/scripts/omp.zsh +++ b/src/shell/scripts/omp.zsh @@ -7,6 +7,10 @@ export CONDA_PROMPT_MODIFIER=false export ZLE_RPROMPT_INDENT=0 export OSTYPE=$OSTYPE +# disable all known python virtual environment prompts +export VIRTUAL_ENV_DISABLE_PROMPT=1 +export PYENV_VIRTUALENV_DISABLE_PROMPT=1 + _omp_executable=::OMP:: _omp_tooltip_command=''