summaryrefslogtreecommitdiffstats
path: root/bin/ossh_bash_completion
blob: 5072161f0809c172d83112f296e3d8a95767b315 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
__ossh_known_hosts(){
    if python -c 'import openshift_ansible' &>/dev/null; then
      /usr/bin/python -c 'from openshift_ansible import multi_ec2; m=multi_ec2.MultiEc2(); m.run(); z=m.result; print "\n".join(["%s.%s" % (host["ec2_tag_Name"],host["ec2_tag_environment"]) for dns, host in z["_meta"]["hostvars"].items() if all(k in host for k in ("ec2_tag_Name", "ec2_tag_environment"))])'

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

    elif [[ -f ~/.ansible/tmp/multi_ec2_inventory.cache ]]; then
      /usr/bin/python -c 'import json,os; loc="%s" % os.path.expanduser("~/.ansible/tmp/multi_ec2_inventory.cache"); z=json.loads(open(loc).read()); print "\n".join(["%s.%s" % (host["ec2_tag_Name"],host["ec2_tag_environment"]) for dns, host in z["_meta"]["hostvars"].items() if all(k in host for k in ("ec2_tag_Name", "ec2_tag_environment"))])'

    fi
}

_ossh()
{
    local cur prev known_hosts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    known_hosts="$(__ossh_known_hosts)"
    COMPREPLY=( $(compgen -W "${known_hosts}" -- ${cur}))

    return 0
}
complete -F _ossh ossh oscp

__opssh_known_hosts(){
    if python -c 'import openshift_ansible' &>/dev/null; then
      /usr/bin/python -c 'from openshift_ansible.multi_ec2 import MultiEc2; m=MultiEc2(); m.run(); print "\n".join(["%s" % (host["ec2_tag_host-type"]) for dns, host in m.result["_meta"]["hostvars"].items() if "ec2_tag_host-type" in host])'

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

    elif [[ -f ~/.ansible/tmp/multi_ec2_inventory.cache ]]; then
      /usr/bin/python -c 'import json,os; loc="%s" % os.path.expanduser("/dev/shm/.ansible/tmp/multi_ec2_inventory.cache"); z=json.loads(open(loc).read()); print "\n".join(["%s" % (host["ec2_tag_host-type"]) for dns, host in z["_meta"]["hostvars"].items() if "ec2_tag_host-type" in host])'

    fi
}

_opssh()
{
    local cur prev known_hosts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    known_hosts="$(__opssh_known_hosts)"
    COMPREPLY=( $(compgen -W "${known_hosts}" -- ${cur}))

    return 0
}
complete -F _opssh opssh