From dd5bc77576ce933474a80a66be1bbc13f659a8a6 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Tue, 18 Oct 2022 10:45:48 +0200 Subject: [PATCH] feat(pwsh): allow disabling folder fallback resolves #2949 --- src/shell/scripts/omp.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/shell/scripts/omp.ps1 b/src/shell/scripts/omp.ps1 index 749e2b2b..f5d0a848 100644 --- a/src/shell/scripts/omp.ps1 +++ b/src/shell/scripts/omp.ps1 @@ -3,6 +3,9 @@ if ($null -ne (Get-Module -Name "oh-my-posh-core")) { Remove-Module -Name "oh-my-posh-core" -Force } +# enable the fallback for non-existing folders +$env:POSH_UNKNOWN_DIR_REDIRECT = $true + # 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 { @@ -85,7 +88,7 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock { if ($PWD.Provider.Name -eq 'FileSystem') { # make sure we're in a valid directory # if not, go back HOME - if (-not (Test-Path -Path $PWD)) { + if (-not (Test-Path -Path $PWD) -and $env:POSH_UNKNOWN_DIR_REDIRECT -eq $true) { Write-Host "Unable to find the current directory, falling back to $HOME" -ForegroundColor Red Set-Location $HOME }