Script directory for a PowerShell profile. https://blog.lksz.me/keeping-track-of-everything/#-mypsscriptroot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.3 KiB

  1. [CmdletBinding(SupportsShouldProcess)]param()
  2. $local:myAliases = [ordered]@{}
  3. $myAliases.sudo = 'Invoke-Sudo'
  4. $myAliases.vi = 'Edit-TextFile'
  5. $myAliases.vim = 'Edit-TextFile'
  6. $myAliases.nvim = 'Edit-TextFile'
  7. $myAliases.nvim = 'Edit-TextFile'
  8. $myAliases.l = 'ls.ps1'
  9. $myAliases.ll = 'ls.ps1'
  10. #######################################################################
  11. $local:IsVerbose = [bool]($PSBoundParameters['Verbose'])
  12. $local:MyAliasScope = 1
  13. $local:oldAliases = . Get-MyAliases
  14. $oldAliases = Get-Alias -Scope $MyAliasScope |
  15. Where-Object Name -in $($oldAliases.Name + $myAliases.Keys)
  16. if( $oldAliases -and $IsVerbose ) {
  17. Write-Verbose "Removing: $($oldAliases.Name -join ', ')"
  18. }
  19. $oldAliases | Remove-Alias -Scope $MyAliasScope
  20. Get-ChildItem (Join-Path $MyPSScriptRoot '*.ps1') |
  21. ForEach-Object {
  22. Set-Alias $($_.BaseName) $_.FullName -Scope $MyAliasScope
  23. }
  24. foreach( $local:alias in $myAliases.Keys ) {
  25. Set-Alias -Name $alias -Value $myAliases[$alias] -Description '#MyAlias' -Scope $MyAliasScope
  26. }
  27. if( $(. Get-ScopeDepth) -gt 0 ) { Write-Host -ForegroundColor Red "Try sourcing Reload-MyScripts instead of just running it" }
  28. Get-ChildItem $(Join-Path $MyPSScriptRoot profile.d) -Filter '*.ps1' | ForEach-Object { ". '$($_.FullName)';" } | Invoke-Expression