completion-templates.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. export const completionShTemplate = `###-begin-{{app_name}}-completions-###
  2. #
  3. # yargs command completion script
  4. #
  5. # Installation: {{app_path}} {{completion_command}} >> ~/.bashrc
  6. # or {{app_path}} {{completion_command}} >> ~/.bash_profile on OSX.
  7. #
  8. _{{app_name}}_yargs_completions()
  9. {
  10. local cur_word args type_list
  11. cur_word="\${COMP_WORDS[COMP_CWORD]}"
  12. args=("\${COMP_WORDS[@]}")
  13. # ask yargs to generate completions.
  14. type_list=$({{app_path}} --get-yargs-completions "\${args[@]}")
  15. COMPREPLY=( $(compgen -W "\${type_list}" -- \${cur_word}) )
  16. # if no match was found, fall back to filename completion
  17. if [ \${#COMPREPLY[@]} -eq 0 ]; then
  18. COMPREPLY=()
  19. fi
  20. return 0
  21. }
  22. complete -o bashdefault -o default -F _{{app_name}}_yargs_completions {{app_name}}
  23. ###-end-{{app_name}}-completions-###
  24. `;
  25. export const completionZshTemplate = `#compdef {{app_name}}
  26. ###-begin-{{app_name}}-completions-###
  27. #
  28. # yargs command completion script
  29. #
  30. # Installation: {{app_path}} {{completion_command}} >> ~/.zshrc
  31. # or {{app_path}} {{completion_command}} >> ~/.zprofile on OSX.
  32. #
  33. _{{app_name}}_yargs_completions()
  34. {
  35. local reply
  36. local si=$IFS
  37. IFS=$'\n' reply=($(COMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" {{app_path}} --get-yargs-completions "\${words[@]}"))
  38. IFS=$si
  39. _describe 'values' reply
  40. }
  41. compdef _{{app_name}}_yargs_completions {{app_name}}
  42. ###-end-{{app_name}}-completions-###
  43. `;