Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save albertvaka/b50974ddefdd8ff0625eb31982091034 to your computer and use it in GitHub Desktop.
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
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