Last active
March 12, 2024 15:03
-
-
Save albertvaka/b50974ddefdd8ff0625eb31982091034 to your computer and use it in GitHub Desktop.
Powershell 'cd' that behaves properly: zero args bring you home, passing '-' brings you to the previous dir
This file contains 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
del alias:cd -Force # Remove builtin cd alias to Set-Location | |
function cd { | |
$pwd = Get-Location | |
if ($args.Count -eq 0) { | |
Set-Location ~ | |
} elseif ($args[0] -eq "-") { | |
Set-Location @global:OLDPWD | |
} else { | |
Set-Location @args | |
} | |
$global:OLDPWD = $pwd | |
} | |
# Bonus: Make autocompletion work like on bash: | |
Set-PSReadlineKeyHandler -Key Tab -Function Complete | |
# Or like in zsh: | |
# Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment