설명 없음

powershell 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright (c) 2014 Jason Jarrett
  2. #
  3. # Tab completion for the `gulp`
  4. #
  5. # Usage:
  6. #
  7. # To enable powershell <tab> completion for gulp you need to be running
  8. # at least PowerShell v3 or greater and add the below to your $PROFILE
  9. #
  10. # Invoke-Expression ((gulp --completion=powershell) -join [System.Environment]::NewLine)
  11. #
  12. #
  13. $gulp_completion_Process = {
  14. param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
  15. # Load up an assembly to read the gulpfile's sha1
  16. if(-not $global:GulpSHA1Managed) {
  17. [Reflection.Assembly]::LoadWithPartialName("System.Security") | out-null
  18. $global:GulpSHA1Managed = new-Object System.Security.Cryptography.SHA1Managed
  19. }
  20. # setup a global (in-memory) cache
  21. if(-not $global:GulpfileShaCache) {
  22. $global:GulpfileShaCache = @{};
  23. }
  24. $cache = $global:GulpfileShaCache;
  25. # Get the gulpfile's sha1
  26. $sha1gulpFile = (resolve-path gulpfile.js -ErrorAction Ignore | %{
  27. $file = [System.IO.File]::Open($_.Path, "open", "read")
  28. [string]::join('', ($global:GulpSHA1Managed.ComputeHash($file) | %{ $_.ToString("x2") }))
  29. $file.Dispose()
  30. })
  31. # lookup the sha1 for previously cached task lists.
  32. if($cache.ContainsKey($sha1gulpFile)){
  33. $tasks = $cache[$sha1gulpFile];
  34. } else {
  35. $tasks = (gulp --tasks-simple).split("`n");
  36. $cache[$sha1gulpFile] = $tasks;
  37. }
  38. $tasks |
  39. where { $_.startswith($commandName) }
  40. Sort-Object |
  41. foreach { New-Object System.Management.Automation.CompletionResult $_, $_, 'ParameterValue', ('{0}' -f $_) }
  42. }
  43. if (-not $global:options) {
  44. $global:options = @{
  45. CustomArgumentCompleters = @{};
  46. NativeArgumentCompleters = @{}
  47. }
  48. }
  49. $global:options['NativeArgumentCompleters']['gulp'] = $gulp_completion_Process
  50. $function:tabexpansion2 = $function:tabexpansion2 -replace 'End\r\n{','End { if ($null -ne $options) { $options += $global:options} else {$options = $global:options}'