Script directory for a PowerShell profile. https://blog.lksz.me/keeping-track-of-everything/#-mypsscriptroot
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.3 KiB

  1. [CmdletBinding(SupportsShouldProcess)]param(
  2. [ArgumentCompleter({ param (
  3. $commandName,
  4. $parameterName,
  5. $wordToComplete,
  6. $commandAst,
  7. $fakeBoundParameters
  8. )
  9. [FunctionName]::_GetValidValues($wordToComplete,$true)
  10. })]
  11. [string[]]$ImportFunction,
  12. [switch]$ForceImport,
  13. [Parameter(Position = 0, ValueFromRemainingArguments = $true)]
  14. [ArgumentCompleter({ param (
  15. $commandName,
  16. $parameterName,
  17. $wordToComplete,
  18. $commandAst,
  19. $fakeBoundParameters
  20. )
  21. [MyScript]::_GetValidValues($wordToComplete,$false)
  22. })]
  23. [string[]]$ScriptName
  24. )
  25. $local:ScriptPaths = @()
  26. foreach( $local:p in $ImportFunction ) {
  27. $local:f = Get-Command $p -Type Function
  28. if( $f ) {
  29. $local:sp = Join-Path $MyPSScriptRoot "$p`.ps1"
  30. if( $ForceImport -or -not (Test-Path $sp) ) {
  31. Export-FunctionSource $p -NoHeader > $sp
  32. } elseif ( -not $ForceImport ) {
  33. throw "$p already exists in Script, to import the function again, use the -Force"
  34. }
  35. $ScriptPaths += $sp
  36. }
  37. }
  38. foreach( $local:p in $ScriptName ) {
  39. $local:sp = Join-Path $MyPSScriptRoot "$p`.ps1"
  40. $ScriptPaths += $sp
  41. }
  42. Edit-TextFile $ScriptPaths
  43. Get-Command Reload-MyScripts -ErrorAction SilentlyContinue |
  44. ForEach-Object { . $_.Definition }