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.

_zola.ps1 5.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using namespace System.Management.Automation
  2. using namespace System.Management.Automation.Language
  3. Register-ArgumentCompleter -Native -CommandName 'zola' -ScriptBlock {
  4. param($wordToComplete, $commandAst, $cursorPosition)
  5. $commandElements = $commandAst.CommandElements
  6. $command = @(
  7. 'zola'
  8. for ($i = 1; $i -lt $commandElements.Count; $i++) {
  9. $element = $commandElements[$i]
  10. if ($element -isnot [StringConstantExpressionAst] -or
  11. $element.StringConstantType -ne [StringConstantType]::BareWord -or
  12. $element.Value.StartsWith('-')) {
  13. break
  14. }
  15. $element.Value
  16. }) -join ';'
  17. $completions = @(switch ($command) {
  18. 'zola' {
  19. [CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Path to a config file other than config.toml')
  20. [CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'Path to a config file other than config.toml')
  21. [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
  22. [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
  23. [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
  24. [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
  25. [CompletionResult]::new('init', 'init', [CompletionResultType]::ParameterValue, 'Create a new Zola project')
  26. [CompletionResult]::new('build', 'build', [CompletionResultType]::ParameterValue, 'Builds the site')
  27. [CompletionResult]::new('serve', 'serve', [CompletionResultType]::ParameterValue, 'Serve the site. Rebuild and reload on change automatically')
  28. [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Prints this message or the help of the given subcommand(s)')
  29. break
  30. }
  31. 'zola;init' {
  32. [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
  33. [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
  34. [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
  35. [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
  36. break
  37. }
  38. 'zola;build' {
  39. [CompletionResult]::new('-u', 'u', [CompletionResultType]::ParameterName, 'Force the base URL to be that value (default to the one in config.toml)')
  40. [CompletionResult]::new('--base-url', 'base-url', [CompletionResultType]::ParameterName, 'Force the base URL to be that value (default to the one in config.toml)')
  41. [CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'Outputs the generated site in the given path')
  42. [CompletionResult]::new('--output-dir', 'output-dir', [CompletionResultType]::ParameterName, 'Outputs the generated site in the given path')
  43. [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
  44. [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
  45. [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
  46. [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
  47. break
  48. }
  49. 'zola;serve' {
  50. [CompletionResult]::new('-i', 'i', [CompletionResultType]::ParameterName, 'Interface to bind on')
  51. [CompletionResult]::new('--interface', 'interface', [CompletionResultType]::ParameterName, 'Interface to bind on')
  52. [CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'Which port to use')
  53. [CompletionResult]::new('--port', 'port', [CompletionResultType]::ParameterName, 'Which port to use')
  54. [CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'Outputs the generated site in the given path')
  55. [CompletionResult]::new('--output-dir', 'output-dir', [CompletionResultType]::ParameterName, 'Outputs the generated site in the given path')
  56. [CompletionResult]::new('-u', 'u', [CompletionResultType]::ParameterName, 'Changes the base_url')
  57. [CompletionResult]::new('--base-url', 'base-url', [CompletionResultType]::ParameterName, 'Changes the base_url')
  58. [CompletionResult]::new('--watch-only', 'watch-only', [CompletionResultType]::ParameterName, 'Do not start a server, just re-build project on changes')
  59. [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
  60. [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
  61. [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
  62. [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
  63. break
  64. }
  65. 'zola;help' {
  66. [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
  67. [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
  68. [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
  69. [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
  70. break
  71. }
  72. })
  73. $completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
  74. Sort-Object -Property ListItemText
  75. }