bash_completion 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env bash
  2. # Copyright (c) 2020, Eric Pailleau <crownedgrouse@wanadoo.fr>
  3. # This file is part of erlang.mk and subject to the terms of the ISC License.
  4. # Date: April 12th 2020
  5. # Bash completion for Erlang.mk
  6. _erlang_mk()
  7. {
  8. local cur prev words cword
  9. _init_completion || return
  10. T=$(make list-templates | cut -d ':' -f 2-)
  11. TP=$(echo -n $T | cut -d '_' -f 1 | tr ' ' '|')
  12. TPP=$(echo -n $T | tr ' ' '|')
  13. case $prev in
  14. make)
  15. COMPREPLY=( $(compgen -W "all app deps fetch-deps list-deps search rel docs install-docs check tests clean distclean help erlang-mk bootstrap bootstrap-lib bootstrap-rel new-app new-lib new new list-templates ct plt dialyze escript eunit shell sphinx xref cover-report all.coverdata" -- "$cur") )
  16. ;;
  17. search)
  18. COMPREPLY=( $(compgen -W 'q=' -- "$cur") ) && compopt -o nospace
  19. ;;
  20. new-app|new-lib)
  21. COMPREPLY=( $(compgen -W 'in=' -- "$cur") ) && compopt -o nospace
  22. ;;
  23. new)
  24. COMPREPLY=( $(compgen -W 't=' -- "$cur") ) && compopt -o nospace
  25. ;;
  26. =)
  27. if [[ ${words[$cword - 2]} == "in" ]]; then
  28. COMPREPLY=( $(compgen -W "$(ls apps 2>/dev/null)" -- "$cur") ) && compopt -o nospace
  29. else
  30. if [[ ${words[$cword - 2]} == "t" ]]; then
  31. COMPREPLY=( $(compgen -W "$T" -- "$cur") ) && compopt -o nospace
  32. fi
  33. fi
  34. ;;
  35. $TP)
  36. COMPREPLY=( $(compgen -W "$T" -- "$cur") ) && compopt -o nospace
  37. ;;
  38. $TPP)
  39. COMPREPLY=( $(compgen -W 'n=' -- "$cur") ) && compopt -o nospace
  40. ;;
  41. *)
  42. if [[ "$prev" == "in" && "$cur" == '=' ]]; then
  43. test -d apps && echo 1>&2
  44. test -d apps && echo $(ls apps 2>/dev/null)
  45. COMPREPLY=( $(compgen -W "$(ls apps 2>/dev/null )" -- "$cur") ) && compopt -o nospace
  46. fi
  47. if [[ "$prev" == "t" && "$cur" == '=' ]]; then
  48. echo 1>&2
  49. echo $T 1>&2
  50. COMPREPLY=( $(compgen -W "$T" -- "$cur") ) && compopt -o nospace
  51. fi
  52. if [[ $(echo "$T" | tr ' ' "\n" | grep "$prev") ]]; then
  53. COMPREPLY=( $(compgen -W 'n=' -- "$cur") ) && compopt -o nospace
  54. fi
  55. if [[ ${words[$cword - 1]} == "n=" || ${words[$cword - 1]} == "n" ]]; then
  56. COMPREPLY=( $(compgen -W 'in=' -- "$cur") ) && compopt -o nospace
  57. fi
  58. if [[ ${words[$cword - 3]} == "n" ]]; then
  59. COMPREPLY=( $(compgen -W 'in=' -- "$cur") ) && compopt -o nospace
  60. fi
  61. ;;
  62. esac
  63. case $cur in
  64. all|bootstrap|list|list-|new|new-)
  65. echo 1>&2
  66. make help | grep "^ $cur" 1>&2
  67. return
  68. ;;
  69. esac
  70. } &&
  71. complete -F _erlang_mk make