Reload-MyAliases is now Reload-MyScripts
🔖 https://blog.lksz.me/editing-with-ease/ ✏️ Fixed $MyPSScriptRoot typo ✨ Get-ScopeDepth 🐛 Get-MyAliases didn't work correctly when sub-scoped, fixed the issue 🚚 Reload-MyAliases is now Reload-MyScripts 🐛 Reload-MyScripts loads scripts from $MyPSScriptRoot/profile.d subdir 📝 README updated to reflect change of script name and typo
This commit is contained in:
parent
bb2488e591
commit
06052cfa29
14 changed files with 186 additions and 13 deletions
37
Reload-MyScripts.ps1
Normal file
37
Reload-MyScripts.ps1
Normal file
|
@ -0,0 +1,37 @@
|
|||
[CmdletBinding(SupportsShouldProcess)]param()
|
||||
|
||||
$local:myAliases = [ordered]@{}
|
||||
$myAliases.sudo = 'Invoke-Sudo'
|
||||
$myAliases.vi = 'Edit-TextFile'
|
||||
$myAliases.vim = 'Edit-TextFile'
|
||||
$myAliases.nvim = 'Edit-TextFile'
|
||||
$myAliases.nvim = 'Edit-TextFile'
|
||||
$myAliases.l = 'ls.ps1'
|
||||
$myAliases.ll = 'ls.ps1'
|
||||
|
||||
#######################################################################
|
||||
|
||||
$local:IsVerbose = [bool]($PSBoundParameters['Verbose'])
|
||||
|
||||
$local:MyAliasScope = 1
|
||||
|
||||
$local:oldAliases = . Get-MyAliases
|
||||
|
||||
$oldAliases = Get-Alias -Scope $MyAliasScope |
|
||||
Where-Object Name -in $($oldAliases.Name + $myAliases.Keys)
|
||||
|
||||
if( $oldAliases -and $IsVerbose ) {
|
||||
Write-Verbose "Removing: $($oldAliases.Name -join ', ')"
|
||||
}
|
||||
$oldAliases | Remove-Alias -Scope $MyAliasScope
|
||||
Get-ChildItem (Join-Path $MyPSScriptRoot '*.ps1') |
|
||||
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
|
||||
}
|
||||
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue