diff options
Diffstat (limited to 'completions/iptables')
-rw-r--r-- | completions/iptables | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/completions/iptables b/completions/iptables index ffb905b..d0c0ec1 100644 --- a/completions/iptables +++ b/completions/iptables @@ -1,51 +1,55 @@ # bash completion for iptables -*- shell-script -*- -_iptables() +_comp_cmd_iptables() { - local cur prev words cword split - _init_completion -s || return + local cur prev words cword was_split comp_args + _comp_initialize -s -- "$@" || return - local table chain='s/^Chain \([^ ]\{1,\}\).*$/\1/p' + local table="" chain='s/^Chain \([^ ]\{1,\}\).*$/\1/p' + local targets='ACCEPT DROP LOG ULOG REJECT' + local IFS=$' \t\n' # for ${table:+-t "$table"} [[ ${words[*]} =~ [[:space:]]-(t|-table=?)[[:space:]]*([^[:space:]]+) ]] && - table="-t ${BASH_REMATCH[2]}" + table=${BASH_REMATCH[2]} case $prev in -*[AIDRPFXLZ]) - COMPREPLY=($(compgen -W '`"$1" $table -nL 2>/dev/null | \ - command sed -ne "s/^Chain \([^ ]\{1,\}\).*$/\1/p"`' -- "$cur")) + _comp_compgen_split -- "$( + "$1" ${table:+-t "$table"} -nL 2>/dev/null | + command sed -ne 's/^Chain \([^ ]\{1,\}\).*$/\1/p' + )" ;; -*t) - COMPREPLY=($(compgen -W 'nat filter mangle' -- "$cur")) + _comp_compgen -- -W 'nat filter mangle' ;; -j) - if [[ $table == "-t filter" || -z $table ]]; then - COMPREPLY=($(compgen -W 'ACCEPT DROP LOG ULOG REJECT - `"$1" $table -nL 2>/dev/null | command sed -ne "$chain" \ - -e "s/INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING//"`' -- \ - "$cur")) - elif [[ $table == "-t nat" ]]; then - COMPREPLY=($(compgen -W 'ACCEPT DROP LOG ULOG REJECT MIRROR SNAT - DNAT MASQUERADE `"$1" $table -nL 2>/dev/null | \ - command sed -ne "$chain" -e "s/OUTPUT|PREROUTING|POSTROUTING//"`' \ - -- "$cur")) - elif [[ $table == "-t mangle" ]]; then - COMPREPLY=($(compgen -W 'ACCEPT DROP LOG ULOG REJECT MARK TOS - `"$1" $table -nL 2>/dev/null | command sed -ne "$chain" \ - -e "s/INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING//"`' -- \ - "$cur")) + if [[ $table == "filter" || ! $table ]]; then + _comp_compgen -- -W '$targets' + _comp_compgen -a split -- "$("$1" ${table:+-t "$table"} -nL \ + 2>/dev/null | command sed -ne "$chain" \ + -e 's/INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING//')" + elif [[ $table == "nat" ]]; then + _comp_compgen -- -W '$targets MIRROR SNAT DNAT MASQUERADE' + _comp_compgen -a split -- "$("$1" -t "$table" -nL 2>/dev/null | + command sed -ne "$chain" \ + -e 's/OUTPUT|PREROUTING|POSTROUTING//')" + elif [[ $table == "mangle" ]]; then + _comp_compgen -- -W '$targets MARK TOS' + _comp_compgen -a split -- "$("$1" -t "$table" -nL 2>/dev/null | + command sed -ne "$chain" \ + -e 's/INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING//')" fi ;; *) if [[ $cur == -* ]]; then - COMPREPLY=($(compgen -W '$("$1" --help 2>&1 | - command sed -e "s/^\[\!\]//" | _parse_help -)' -- "$cur")) + _comp_compgen_help - <<<"$("$1" --help 2>&1 | + command sed -e "s/^\[\!\]//")" [[ ${COMPREPLY-} == *= ]] && compopt -o nospace fi ;; esac } && - complete -F _iptables iptables + complete -F _comp_cmd_iptables iptables # ex: filetype=sh |