# bash completion for ivpn

_ivpn()
{
    local cur opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}" # current word
    cmd="${COMP_WORDS[1]}"          # next word after "ivpn", e.g.: $ ivpn <cmd> ...

    opts="status connect disconnect connection servers firewall splittun exclude wgkeys dns antitracker logs login logout account eaa autoconnect wifi -h"

    case "${cmd}" in
        status)
            local status_opts=" -h"
            COMPREPLY=( $(compgen -W "${status_opts}" -- ${cur}) )
            return 0
            ;;
        connect)
            local connect_opts="-city -cc -country_code -c -country -l -location -filter_invert -f -fastest -last -any -exit_svr -p -protocol -mtu -ipv6tunnel -show_ports -port -fw_off -dns -antitracker -antitracker_hard -o -obfsproxy -v2ray -h"
            COMPREPLY=( $(compgen -W "${connect_opts}" -- ${cur}) )
            return 0
            ;;
        disconnect)
            local disconnect_opts=" -h"
            COMPREPLY=( $(compgen -W "${disconnect_opts}" -- ${cur}) )
            return 0
            ;;
        connection)
            local connection_opts="-pause -resume -h"
            COMPREPLY=( $(compgen -W "${connection_opts}" -- ${cur}) )
            return 0
            ;;
        servers)
            local servers_opts="-city -cc -country_code -c -country -l -location -filter_invert -ping -p -protocol -load -hosts -h"
            COMPREPLY=( $(compgen -W "${servers_opts}" -- ${cur}) )
            return 0
            ;;
        firewall)
            local firewall_opts="-status -ivpn_access_allow -ivpn_access_block -persistent_off -persistent_on -lan_allow -lan_block -exceptions -off -on -h"
            COMPREPLY=( $(compgen -W "${firewall_opts}" -- ${cur}) )
            return 0
            ;;
        splittun)
            local splittun_opts="-status -status_full -clean -appadd -appremove -inverse_on -inverse_off -inverse_allow_default_connection -inverse_restrict_dns -on -off -h"
            COMPREPLY=( $(compgen -W "${splittun_opts}" -- ${cur}) )
            return 0
            ;;
        exclude)
            local exclude_opts="-eaa -h"
            COMPREPLY=( $(compgen -W "${exclude_opts}" -- ${cur}) )
            return 0
            ;;
        wgkeys)
            local wgkeys_opts="-status -regenerate -rotation_interval -h"
            COMPREPLY=( $(compgen -W "${wgkeys_opts}" -- ${cur}) )
            return 0
            ;;
        dns)
            local dns_opts="-add -management -doh -off -h"
            COMPREPLY=( $(compgen -W "${dns_opts}" -- ${cur}) )
            return 0
            ;;
        antitracker)
            local antitracker_opts="-off -on -on_hardcore -show_blocklists -h"
            COMPREPLY=( $(compgen -W "${antitracker_opts}" -- ${cur}) )
            return 0
            ;;
        logs)
            local logs_opts="-show -off -on -h"
            COMPREPLY=( $(compgen -W "${logs_opts}" -- ${cur}) )
            return 0
            ;;
        login)
            local login_opts="-force -h"
            COMPREPLY=( $(compgen -W "${login_opts}" -- ${cur}) )
            return 0
            ;;
        logout)
            local logout_opts="-reset_settings -firewall_off -h"
            COMPREPLY=( $(compgen -W "${logout_opts}" -- ${cur}) )
            return 0
            ;;
        account)
            local account_opts=" -h"
            COMPREPLY=( $(compgen -W "${account_opts}" -- ${cur}) )
            return 0
            ;;
        eaa)
            local eaa_opts="-status -off -on -h"
            COMPREPLY=( $(compgen -W "${eaa_opts}" -- ${cur}) )
            return 0
            ;;
        autoconnect)
            local autoconnect_opts="-status -on_launch -h"
            COMPREPLY=( $(compgen -W "${autoconnect_opts}" -- ${cur}) )
            return 0
            ;;
        wifi)
            local wifi_opts="-status -trusted_control -default_trust_status -set_trusted_action -set_trusted_network -reset_settings -h"
            COMPREPLY=( $(compgen -W "${wifi_opts}" -- ${cur}) )
            return 0
            ;;
        -*)
            return 0
            ;;
    esac

   COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
   return 0
}
complete -F _ivpn ivpn

