bash_completion.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/bash
  2. # http://stackoverflow.com/a/246128
  3. SOURCE="${BASH_SOURCE[0]}"
  4. while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  5. DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  6. SOURCE="$(readlink "$SOURCE")"
  7. [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
  8. done
  9. JAKE_BIN_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  10. # http://stackoverflow.com/a/12495480
  11. # http://stackoverflow.com/a/28647824
  12. _auto_jake()
  13. {
  14. local cur
  15. local -a COMPGEN=()
  16. _get_comp_words_by_ref -n : -c cur
  17. # run auto-completions in jake via our auto_complete.js wrapper
  18. local -a auto_complete_info=( $(export COMP_LINE="${COMP_LINE}" && ${JAKE_BIN_DIR}/auto_complete.js "$cur" "${3}") )
  19. # check reply flag
  20. local reply_flag="${auto_complete_info[0]}"
  21. if [[ "${reply_flag}" == "no-complete" ]]; then
  22. return 1
  23. fi
  24. local auto_completions=("${auto_complete_info[@]:1}")
  25. COMPGEN=( $(compgen -W "${auto_completions[*]}" -- "$cur") )
  26. COMPREPLY=( "${COMPGEN[@]}" )
  27. __ltrim_colon_completions "$cur"
  28. # do we need another space??
  29. if [[ "${reply_flag}" == "yes-space" ]]; then
  30. COMPREPLY=( "${COMPGEN[@]}" " " )
  31. fi
  32. return 0
  33. }
  34. complete -o default -F _auto_jake jake