Managing SSH chroots to backup a lot of machines
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.

30 lines
850 B

  1. # bkctld(8) completion
  2. #
  3. # Copyright (c) 2017 Victor Laborie <vlaborie@evolix.fr>
  4. #
  5. # shellcheck shell=bash
  6. function _bkctld()
  7. {
  8. local cur prev commands jails keys
  9. cur=${COMP_WORDS[COMP_CWORD]};
  10. prev=${COMP_WORDS[COMP_CWORD-1]};
  11. commands=$(find /usr/lib/bkctld/ -name "bkctld-*" -exec basename {} \; | sed 's/^bkctld-//')
  12. if [ $COMP_CWORD -eq 1 ]; then
  13. COMPREPLY=($(compgen -W '${commands}' -- ${cur}))
  14. elif [ $COMP_CWORD -eq 2 ]; then
  15. [ -f /etc/default/bkctld ] && source /etc/default/bkctld
  16. [ -z "${JAILDIR}" ] && JAILDIR='/backup/jails'
  17. jails=$(ls "${JAILDIR}")
  18. COMPREPLY=($(compgen -W "${jails}" -- ${cur}))
  19. elif [ $COMP_CWORD -eq 3 ]; then
  20. keys=$(ls *.pub)
  21. COMPREPLY=($(compgen -W "${keys}" -- ${cur}))
  22. fi
  23. return 0
  24. } &&
  25. complete -F _bkctld bkctld