Public/Enter-Location.ps1
function Enter-Location { [CmdletBinding()] param( [Parameter(Mandatory = $true, Position = 0)] [string] $name, [Parameter(Mandatory = $false, Position = 1)] [uint32] $depth = 5, [switch] $startsWith ) if ($startsWith.IsPresent) { $filter = "$name*" } else { $filter = "*$name*" } $v = Get-ChildItem -Directory -Recurse -Depth $depth -Filter $filter -ErrorAction Ignore | Select-Object -First 1 if ($null -ne $v) { Set-Location -Path $($v.FullName) } else { # Fall back to trying to navigate to the value passed in. This will allow the user # to use jt everywhere they would have used cd. Set-Location -Path $name -ErrorAction SilentlyContinue -ErrorVariable LocationError # Log this error with this command name and not Set-Location if ($LocationError) { Write-Host "Enter-Location: $($LocationError.Exception.Message)" -ForegroundColor Red } } } Set-Alias jt Enter-Location Set-Alias etl Enter-Location |