From 0ad9c248111eda25d76becf4badee76dfcbe9355 Mon Sep 17 00:00:00 2001 From: ianmacd <> Date: Tue, 8 Jan 2002 00:26:49 +0000 Subject: [PATCH] improve _iptables() with some chain name completion --- bash_completion | 52 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/bash_completion b/bash_completion index 02f3ca76..6c38215c 100644 --- a/bash_completion +++ b/bash_completion @@ -2,7 +2,7 @@ # # # @@ -1213,15 +1213,53 @@ complete -F _tar -o default tar have iptables && _iptables() { - local cur prev + local cur prev table chain COMPREPLY=() - cur=${COMP_WORDS[COMP_CWORD]} + cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} - - [ "$prev" = -t ] && COMPREPLY=( $( compgen -W 'nat filter mangle' $cur ) ) -} - [ "$have" ] && complete -F _iptables iptables + chain='s/^Chain \([^ ]\+\).*$/\1/p' + + if [[ $COMP_LINE == *-t\ *filter* ]]; then + table="-t filter" + elif [[ $COMP_LINE == *-t\ *nat* ]]; then + table="-t nat" + elif [[ $COMP_LINE == *-t\ *mangle* ]]; then + table="-t mangle" + fi + + case "$prev" in + -*[AIDPFXL]) + COMPREPLY=( $( compgen -W '`iptables $table -nL | sed -ne "s/^Chain \([^ ]\+\).*$/\1/p"`' $cur ) ) + ;; + -*t) + COMPREPLY=( $( compgen -W 'nat filter mangle' $cur ) ) + ;; + -j) + if [ "$table" = "-t filter" -o "$table" = "" ]; then + COMPREPLY=( $( compgen -W 'ACCEPT DROP LOG ULOG REJECT \ + `iptables $table -nL | 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 `iptables $table -nL | \ + sed -ne "$chain" -e "s/OUTPUT|PREROUTING|POSTROUTING//"`' \ + $cur ) ) + elif [ "$table" = "-t mangle" ]; then + COMPREPLY=( $( compgen -W 'ACCEPT DROP LOG ULOG REJECT \ + MARK TOS `iptables $table -nL | sed -ne "$chain" \ + -e "s/INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING//"`' \ + $cur ) ) + fi + ;; + *) + ;; + esac + +} +[ "$have" ] && complete -F _iptables iptables +complete -F _iptables iptables # tcpdump(8) completion #