ossh_zsh_completion 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. #compdef ossh oscp
  2. _ossh_known_hosts(){
  3. if python -c 'import openshift_ansible' &>/dev/null; then
  4. print $(/usr/bin/python -c 'from openshift_ansible import multi_inventory; m=multi_inventory.MultiInventory(); m.run(); z=m.result; print "\n".join([name for name in z["_meta"]["hostvars"].keys()])')
  5. elif [[ -f /dev/shm/.ansible/tmp/multi_inventory.cache ]]; then
  6. print $(/usr/bin/python -c 'import json; loc="/dev/shm/.ansible/tmp/multi_inventory.cache"; z=json.loads(open(loc).read()); print "\n".join([name for name in z["_meta"]["hostvars"].keys() ])')
  7. elif [[ -f ~/.ansible/tmp/multi_inventory.cache ]]; then
  8. print $(/usr/bin/python -c 'import json,os; loc="%s" % os.path.expanduser("~/.ansible/tmp/multi_inventory.cache"); z=json.loads(open(loc).read()); print "\n".join([name for name in z["_meta"]["hostvars"].keys() ])')
  9. fi
  10. }
  11. _ossh(){
  12. local curcontext="$curcontext" state line
  13. typeset -A opt_args
  14. #_arguments "*:Hosts:_ossh_known_hosts"
  15. _arguments -s : \
  16. "*:hosts:->hosts"
  17. case "$state" in
  18. hosts)
  19. _values 'hosts' $(_ossh_known_hosts)
  20. ;;
  21. esac
  22. }
  23. _ossh "$@"