Created
January 14, 2025 13:51
-
-
Save nohwnd/50fbbd17442b58380853e0725a387aa2 to your computer and use it in GitHub Desktop.
cd that navigates to parent folder when you give it path to file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Set-LocationButBetter { | |
param ( | |
[Parameter( | |
Mandatory, | |
ValueFromPipeline, | |
ValueFromPipelineByPropertyName | |
)] | |
$Path | |
) | |
process { | |
if ([System.IO.File]::Exists($Path)) { | |
Set-Location (Split-Path $Path -Parent) | |
} | |
else { | |
Set-Location $Path | |
} | |
} | |
} | |
Remove-Item alias:cd | |
Set-Alias -Name cd -Value Set-LocationButBetter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment