script.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package completion
  2. import "fmt"
  3. var zsh = []byte(fmt.Sprintf(`#compdef $PROG
  4. _cli_zsh_autocomplete() {
  5. local -a opts
  6. local cur
  7. cur=${words[-1]}
  8. if [[ "$cur" == "-"* ]]; then
  9. opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} ${cur} --%s)}")
  10. else
  11. opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --%s)}")
  12. fi
  13. if [[ "${opts[1]}" != "" ]]; then
  14. _describe 'values' opts
  15. else
  16. _files
  17. fi
  18. return
  19. }
  20. compdef _cli_zsh_autocomplete $PROG
  21. `, BashCompletionFlag, BashCompletionFlag))
  22. var bash = []byte(fmt.Sprintf(`#! /bin/bash
  23. : ${PROG:=$(basename ${BASH_SOURCE})}
  24. _cli_bash_autocomplete() {
  25. if [[ "${COMP_WORDS[0]}" != "source" ]]; then
  26. local cur opts base
  27. COMPREPLY=()
  28. cur="${COMP_WORDS[COMP_CWORD]}"
  29. if [[ "$cur" == "-"* ]]; then
  30. opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --%s )
  31. else
  32. opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --%s )
  33. fi
  34. COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
  35. return 0
  36. fi
  37. }
  38. complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG
  39. unset PROG
  40. `, BashCompletionFlag, BashCompletionFlag))