clevis 638 B

1234567891011121314151617181920212223242526
  1. # bash completion support for clevis
  2. _clevis()
  3. {
  4. dir=$(dirname $(which clevis))
  5. cur=${COMP_WORDS[COMP_CWORD]}
  6. field=$(($COMP_CWORD + 1))
  7. if [[ ${COMP_WORDS[COMP_CWORD-1]} == "clevis" ]]; then
  8. name=clevis-*
  9. fi
  10. if [[ ${COMP_WORDS[COMP_CWORD-2]} == "clevis" ]]; then
  11. name=clevis-${COMP_WORDS[COMP_CWORD-1]}-*
  12. fi
  13. suggestions=$(find $dir -name $name | cut -d '-' -f$field | sort | uniq)
  14. if [[ -n $cur ]]; then
  15. suggestions=$(for word in ${suggestions[@]}; do echo $word | grep $cur; done)
  16. fi
  17. COMPREPLY=($(compgen -W "$suggestions" -- "$cur"))
  18. }
  19. complete -F _clevis clevis