/usr/share/bash-completion/completions/firewall-cmd is in firewalld 0.3.7-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | # bash completion for firewall-cmd -*- shell-script -*-
# Copyright (C) 2013 Red Hat, Inc.
#
# Authors:
# Jiri Popelka <jpopelka@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# TODO: find a way how to get the following options from firewall-cmd
OPTIONS_LOCKDOWN="--add-lockdown-whitelist-command= --remove-lockdown-whitelist-command= \
--query-lockdown-whitelist-command= --list-lockdown-whitelist-commands \
--add-lockdown-whitelist-context= --remove-lockdown-whitelist-context= \
--query-lockdown-whitelist-context= --list-lockdown-whitelist-contexts \
--add-lockdown-whitelist-uid= --remove-lockdown-whitelist-uid= \
--query-lockdown-whitelist-uid= --list-lockdown-whitelist-uids \
--add-lockdown-whitelist-user= --remove-lockdown-whitelist-user= \
--query-lockdown-whitelist-user= --list-lockdown-whitelist-users"
# can be used as standalone or with --permanent
OPTIONS_CONFIG="--get-zones --get-services --get-icmptypes
${OPTIONS_LOCKDOWN} --list-all-zones"
OPTIONS_ZONE_INTERFACES_SOURCES="\
--add-interface= --remove-interface= --query-interface= \
--list-interfaces --change-interface= --change-zone= \
--add-source= --remove-source= --query-source= \
--change-source= --list-sources"
OPTIONS_ZONE_ACTION_ACTION="--add-service= --remove-service= --query-service= \
--add-port= --remove-port= --query-port= \
--add-icmp-block= --remove-icmp-block= --query-icmp-block= \
--add-forward-port= --remove-forward-port= --query-forward-port="
OPTIONS_ZONE_ADAPT_QUERY="--add-rich-rule --remove-rich-rule --query-rich-rule \
--add-masquerade --remove-masquerade --query-masquerade \
--list-services --list-ports --list-icmp-blocks \
--list-forward-ports --list-rich-rules --list-all"
# can be used with/without preceding --zone=<zone>
OPTIONS_ZONE="${OPTIONS_ZONE_INTERFACES_SOURCES} \
${OPTIONS_ZONE_ACTION_ACTION} ${OPTIONS_ZONE_ADAPT_QUERY}"
# can be used after --permanent
OPTIONS_PERMANENT="${OPTIONS_CONFIG} --zone= ${OPTIONS_ZONE}"
OPTIONS_DIRECT="--passthrough \
--add-chain --remove-chain --query-chain --get-chains --get-all-chains \
--add-rule --remove-rule --query-rule --get-rules --get-all-rules"
OPTIONS_DIRECT_PERMANENT="--add-passthrough --remove-passthrough \
--query-passthrough --get-passthroughs --get-all-passthroughs"
# these all can be used as a "first" option
OPTIONS_GENERAL="--help --version \
--state --reload --complete-reload \
--panic-on --panic-off --query-panic \
--lockdown-on --lockdown-off --query-lockdown \
--get-default-zone --set-default-zone= --get-active-zones \
--get-zone-of-interface= --get-zone-of-interface= \
${OPTIONS_CONFIG} \
--zone= ${OPTIONS_ZONE} \
--permanent --direct"
_firewall_cmd()
{
local cur prev words cword split
_init_completion -s || return
firewall-cmd --state 1> /dev/null || return
case $prev in
--zone|--set-default-zone)
COMPREPLY=( $( compgen -W '`firewall-cmd --get-zones`' -- "$cur" ) )
;;
--zone=*)
COMPREPLY=( $( compgen -W "${OPTIONS_ZONE}" -- "$cur" ) )
;;
--*-service)
COMPREPLY=( $( compgen -W '`firewall-cmd --get-services`' -- "$cur" ) )
;;
--*-icmp-block)
COMPREPLY=( $( compgen -W '`firewall-cmd --get-icmptypes`' -- "$cur" ) )
;;
--add-rich-rule=*|--add-service=*|--add-port=*|--add-icmp-block=*|--add-forward-port=*|--add-masquerade)
opts=""
[[ ${words[@]} == *--permanent* ]] || opts="--permanent --timeout="
[[ ${words[@]} == *--zone=* ]] || opts="${opts} --zone="
if [ -n "${opts}" ]; then
COMPREPLY=( $( compgen -W "${opts}" -- "$cur" ) )
fi
;;
--*-interface|--change-zone)
_available_interfaces
;;
--permanent)
[[ ${words[@]} == *--direct* ]] && opts="${OPTIONS_DIRECT} ${OPTIONS_DIRECT_PERMANENT}" || opts="${OPTIONS_PERMANENT} --direct"
COMPREPLY=( $( compgen -W "${opts}" -- "$cur" ) )
;;
--direct)
[[ ${words[@]} == *--permanent* ]] && opts="${OPTIONS_DIRECT} ${OPTIONS_DIRECT_PERMANENT}" || opts="${OPTIONS_DIRECT} --permanent"
COMPREPLY=( $( compgen -W "${opts}" -- "$cur" ) )
;;
--passthrough|--*-chain|--get-chains|--*-rule|--get-rules)
COMPREPLY=( $( compgen -W 'ipv4 ipv6 eb' -- "$cur" ) )
;;
ipv4|ipv6|eb)
if [[ ${words[@]} == *--passthrough* ]]; then
return 0
else
COMPREPLY=( $( compgen -W 'nat filter mangle' -- "$cur" ) )
fi
;;
*)
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W "${OPTIONS_GENERAL}" -- "$cur") )
fi
;;
esac
# do not append a space to words that end with =
[[ $COMPREPLY == *= ]] && compopt -o nospace
} &&
complete -F _firewall_cmd firewall-cmd
|