Skip to content

Instantly share code, notes, and snippets.

@nohwnd
Created January 14, 2025 13:51
Show Gist options
  • Save nohwnd/50fbbd17442b58380853e0725a387aa2 to your computer and use it in GitHub Desktop.
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
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