summaryrefslogtreecommitdiffstats
path: root/bin/ossh_zsh_completion
blob: 170ca889b418dbe85eb505d71bae22f657c43904 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#compdef ossh oscp

_ossh_known_hosts(){
    if python -c 'import openshift_ansible' &>/dev/null; then
      print $(/usr/bin/python -c 'from openshift_ansible import multi_inventory; m=multi_inventory.MultiInventory(); m.run(); z=m.result; print "\n".join(["%s.%s" % (host["oo_name"],host["oo_environment"]) for dns, host in z["_meta"]["hostvars"].items() if all(k in host for k in ("oo_name", "oo_environment"))])')

    elif [[ -f /dev/shm/.ansible/tmp/multi_inventory.cache ]]; then
      print $(/usr/bin/python -c 'import json; loc="/dev/shm/.ansible/tmp/multi_inventory.cache"; z=json.loads(open(loc).read()); print "\n".join(["%s.%s" % (host["oo_name"],host["oo_environment"]) for dns, host in z["_meta"]["hostvars"].items() if all(k in host for k in ("oo_name", "oo_environment"))])')

    elif [[ -f ~/.ansible/tmp/multi_inventory.cache ]]; then
      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(["%s.%s" % (host["oo_name"],host["oo_environment"]) for dns, host in z["_meta"]["hostvars"].items() if all(k in host for k in ("oo_name", "oo_environment"))])')

    fi

}
_ossh(){
  local curcontext="$curcontext" state line
  typeset -A opt_args

#_arguments "*:Hosts:_ossh_known_hosts"
    _arguments -s : \
        "*:hosts:->hosts"

    case "$state" in
        hosts)
            _values 'hosts' $(_ossh_known_hosts)
            ;;
    esac

}
_ossh "$@"