Alias
Set an Alias
ps1
New-Alias <alias> <cmd_name>
1
TIP
Use nal
alias for New-Alias
.
NOTE
New-Alias
throws when the alias already exist while Set-Alias
will override it.
Override an Alias
ps1
Set-Alias vim 'nvim --clean -c "source ~/.vimrc"'
1
Or use Set-Item
to manipulate the alias provider directly:
ps1
si alias:vim 'nvim --clean -c "source ~/.vimrc"'
1
TIP
Use sal
alias for Set-Alias
.
Checkout Alias
- Check out by alias
ps1
Get-Alias <alias>
1
TIP
Use gal
alias for Get-Alias
.
Or use Get-Command
ps1
Get-Command <alias>
1
- Check out by command name
ps1
Get-Alias -Definition <cmd_name>
1
Builtin Aliases
Powershell ships with some builtin aliases, checkout by this command:
ps1
Get-Alias | Where-Object { $_.Options -match 'ReadOnly|Constant' }
1
NOTE
Do not use custom aliases for public repository.
CAUTION
Not all builtin aliases are available in all system. See removed aliases
Differ from Bash
Alias in powershell is only a name alias for a command, it can never take any predetermined parameters or flags like in bash.
sh
alias gl='git log' # fine
1
ps1
New-Alias gl 'git log' # not allowed!
1
Should use function instead.
ps1
function gl {
git log
}
1
2
3
2
3