# Copyright (C) 2017 Jason A. Donenfeld . All Rights Reserved. _wg_completion() { if [[ $COMP_CWORD -eq 1 ]]; then COMPREPLY+=( $(compgen -W "show showconf set setconf addconf genkey genpsk pubkey" -- "${COMP_WORDS[1]}") ) return fi case "${COMP_WORDS[1]}" in genkey|genpsk|pubkey|help) return; ;; show|showconf|set|setconf|addconf) ;; *) return; esac if [[ $COMP_CWORD -eq 2 ]]; then local extra [[ ${COMP_WORDS[1]} == show ]] && extra=" all interfaces" COMPREPLY+=( $(compgen -W "$(wg show interfaces 2>/dev/null)$extra" -- "${COMP_WORDS[2]}") ) return fi if [[ $COMP_CWORD -eq 3 && ${COMP_WORDS[1]} == show && ${COMP_WORDS[2]} != interfaces ]]; then COMPREPLY+=( $(compgen -W "public-key private-key preshared-key listen-port peers endpoints allowed-ips fwmark latest-handshakes persistent-keepalive transfer dump" -- "${COMP_WORDS[3]}") ) return fi if [[ $COMP_CWORD -eq 3 && ( ${COMP_WORDS[1]} == setconf || ${COMP_WORDS[1]} == addconf ) ]]; then compopt -o filenames COMPREPLY+=( $(compgen -f -- "${COMP_WORDS[3]}") ) return fi [[ ${COMP_WORDS[1]} == set ]] || return local has_listen_port=0 has_fwmark=0 has_private_key=0 has_preshared_key=0 has_peer=0 has_remove=0 has_endpoint=0 has_persistent_keepalive=0 has_allowed_ips=0 words=() i j for ((i=3;i/dev/null)" -- "${COMP_WORDS[COMP_CWORD]}") ) return fi for ((i=has_peer;i