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.

starwels-tx.bash-completion 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # bash programmable completion for starwels-tx(1)
  2. # Copyright (c) 2016 The Starwels developers
  3. # Distributed under the MIT software license, see the accompanying
  4. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
  5. _starwels_tx() {
  6. local cur prev words=() cword
  7. local starwels_tx
  8. # save and use original argument to invoke starwels-tx for -help
  9. # it might not be in $PATH
  10. starwels_tx="$1"
  11. COMPREPLY=()
  12. _get_comp_words_by_ref -n =: cur prev words cword
  13. case "$cur" in
  14. load=*:*)
  15. cur="${cur#load=*:}"
  16. _filedir
  17. return 0
  18. ;;
  19. *=*) # prevent attempts to complete other arguments
  20. return 0
  21. ;;
  22. esac
  23. if [[ "$cword" == 1 || ( "$prev" != "-create" && "$prev" == -* ) ]]; then
  24. # only options (or an uncompletable hex-string) allowed
  25. # parse starwels-tx -help for options
  26. local helpopts
  27. helpopts=$($starwels_tx -help | sed -e '/^ -/ p' -e d )
  28. COMPREPLY=( $( compgen -W "$helpopts" -- "$cur" ) )
  29. else
  30. # only commands are allowed
  31. # parse -help for commands
  32. local helpcmds
  33. helpcmds=$($starwels_tx -help | sed -e '1,/Commands:/d' -e 's/=.*/=/' -e '/^ [a-z]/ p' -e d )
  34. COMPREPLY=( $( compgen -W "$helpcmds" -- "$cur" ) )
  35. fi
  36. # Prevent space if an argument is desired
  37. if [[ $COMPREPLY == *= ]]; then
  38. compopt -o nospace
  39. fi
  40. return 0
  41. } &&
  42. complete -F _starwels_tx starwels-tx
  43. # Local variables:
  44. # mode: shell-script
  45. # sh-basic-offset: 4
  46. # sh-indent-comment: t
  47. # indent-tabs-mode: nil
  48. # End:
  49. # ex: ts=4 sw=4 et filetype=sh