2020-09-16 15:57:55 +00:00
|
|
|
[CmdletBinding(SupportsShouldProcess)]param()
|
|
|
|
|
|
|
|
$local:myAliases = [ordered]@{}
|
2020-09-18 19:41:58 +00:00
|
|
|
$myAliases.sudo = 'Invoke-Sudo'
|
2020-09-16 15:57:55 +00:00
|
|
|
$myAliases.vi = 'Edit-TextFile'
|
|
|
|
$myAliases.vim = 'Edit-TextFile'
|
|
|
|
$myAliases.nvim = 'Edit-TextFile'
|
|
|
|
$myAliases.nvim = 'Edit-TextFile'
|
2020-09-18 19:41:58 +00:00
|
|
|
$myAliases.l = 'ls.ps1'
|
|
|
|
$myAliases.ll = 'ls.ps1'
|
2020-09-16 15:57:55 +00:00
|
|
|
|
|
|
|
#######################################################################
|
|
|
|
|
|
|
|
$local:IsVerbose = [bool]($PSBoundParameters['Verbose'])
|
|
|
|
|
|
|
|
$local:MyAliasScope = 1
|
|
|
|
|
2020-09-18 19:41:58 +00:00
|
|
|
$local:oldAliases = . Get-MyAliases
|
2020-09-16 15:57:55 +00:00
|
|
|
|
|
|
|
$oldAliases = Get-Alias -Scope $MyAliasScope |
|
|
|
|
Where-Object Name -in $($oldAliases.Name + $myAliases.Keys)
|
|
|
|
|
|
|
|
if( $oldAliases -and $IsVerbose ) {
|
|
|
|
Write-Verbose "Removing: $($oldAliases.Name -join ', ')"
|
|
|
|
}
|
2020-09-30 04:14:51 +00:00
|
|
|
if( Get-Command Remove-Alias -ErrorAction SilentlyContinue ) {
|
|
|
|
$oldAliases | Remove-Alias -Scope $MyAliasScope
|
|
|
|
} else {
|
|
|
|
$oldAliases | ForEach-Object { Remove-Item "Alias:$($_.Name)" }
|
|
|
|
}
|
|
|
|
|
2020-09-18 19:41:58 +00:00
|
|
|
Get-ChildItem (Join-Path $MyPSScriptRoot '*.ps1') |
|
2020-09-16 15:57:55 +00:00
|
|
|
ForEach-Object {
|
|
|
|
Set-Alias $($_.BaseName) $_.FullName -Scope $MyAliasScope
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach( $local:alias in $myAliases.Keys ) {
|
|
|
|
Set-Alias -Name $alias -Value $myAliases[$alias] -Description '#MyAlias' -Scope $MyAliasScope
|
|
|
|
}
|
2020-09-18 19:41:58 +00:00
|
|
|
|
|
|
|
if( $(. Get-ScopeDepth) -gt 0 ) { Write-Host -ForegroundColor Red "Try sourcing Reload-MyScripts instead of just running it" }
|
|
|
|
Get-ChildItem $(Join-Path $MyPSScriptRoot profile.d) -Filter '*.ps1' | ForEach-Object { ". '$($_.FullName)';" } | Invoke-Expression
|