knife_ssh.plugin.zsh 437 B

12345678910111213141516171819
  1. function knife_ssh() {
  2. grep -q $1 ~/.knife_comp~ 2> /dev/null || rm -f ~/.knife_comp~
  3. ssh $(knife node show $1 | awk '/IP:/{print $2}')
  4. }
  5. _knife_ssh() {
  6. if hash knife 2>/dev/null; then
  7. if [[ ! -f ~/.knife_comp~ ]]; then
  8. echo "\nGenerating ~/.knife_comp~..." >&2
  9. knife node list > ~/.knife_comp~
  10. fi
  11. compadd $(< ~/.knife_comp~)
  12. else
  13. echo "Could not find knife" >&2
  14. fi
  15. }
  16. compdef _knife_ssh knife_ssh