Update ufw completion
This commit is contained in:
parent
77cad16cc7
commit
d1469c6e4f
186
src/_ufw
186
src/_ufw
|
@ -28,7 +28,7 @@
|
||||||
# Description
|
# Description
|
||||||
# -----------
|
# -----------
|
||||||
#
|
#
|
||||||
# Completion script for The Uncomplicated Firewall (ufw). (https://launchpad.net/ufw).
|
# Completion script for The Uncomplicated Firewall (ufw) v0.36.2. (https://launchpad.net/ufw).
|
||||||
#
|
#
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Authors
|
# Authors
|
||||||
|
@ -38,108 +38,132 @@
|
||||||
#
|
#
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
_ufw_logging() {
|
_ufw_logging() {
|
||||||
|
local params additional second
|
||||||
|
second=$words[2]
|
||||||
|
|
||||||
local params additional second
|
if [ ! -z $second ]; then
|
||||||
second=$words[2]
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
if [ ! -z $second ]; then
|
params=("on" "off")
|
||||||
return
|
additional=("low" "medium" "high" "full")
|
||||||
fi
|
|
||||||
|
|
||||||
params=(
|
_describe -t params 'on/off' params
|
||||||
"on"
|
_describe -t additional 'level' additional
|
||||||
"off"
|
|
||||||
)
|
|
||||||
|
|
||||||
additional=(
|
|
||||||
"low"
|
|
||||||
"medium"
|
|
||||||
"high"
|
|
||||||
"full"
|
|
||||||
)
|
|
||||||
|
|
||||||
_describe -t params 'on/off' params
|
|
||||||
_describe -t additional 'level' additional
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_ufw_delete() {
|
_ufw_delete() {
|
||||||
local rules complrules second
|
local rules complrules second
|
||||||
|
|
||||||
second=$words[2]
|
second=$words[2]
|
||||||
|
|
||||||
if [ ! -z $second ]; then
|
if [ ! -z $second ]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
complrules=()
|
complrules=()
|
||||||
rules=("${(f)$(ufw status | tr -s ' ' | tail -n +5 | tr -s '\n')}")
|
rules=("${(f)$(ufw status | tr -s ' ' | tail -n +5 | tr -s '\n')}")
|
||||||
|
|
||||||
for ((i=1; i<=${#rules[@]}; i++)); do
|
for ((i=1; i<=${#rules[@]}; i++)); do
|
||||||
complrules+=("$i:$rules[i]");
|
complrules+=("$i:$rules[i]");
|
||||||
done
|
done
|
||||||
|
|
||||||
_describe -t complrules 'Rules' complrules
|
_describe -t complrules 'Rules' complrules
|
||||||
|
}
|
||||||
|
|
||||||
|
_ufw_app() {
|
||||||
|
local ret=1
|
||||||
|
|
||||||
|
local -a subcmds=(
|
||||||
|
"list:list application profiles"
|
||||||
|
"info:show information on profile"
|
||||||
|
"update:update profile"
|
||||||
|
"default:set default application profile"
|
||||||
|
)
|
||||||
|
|
||||||
|
_arguments \
|
||||||
|
"1: :{_describe 'command' subcmds}" \
|
||||||
|
&& ret=0
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
(( $+functions[_flutter_pub_token_subcommand] )) ||
|
||||||
|
_flutter_pub_token_subcommand() {
|
||||||
|
local -a subcommands=(
|
||||||
|
|
||||||
|
)
|
||||||
|
_describe -t subcommands 'subcommand' subcommands "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
_ufw() {
|
_ufw() {
|
||||||
local curcontext="$curcontext" ret=1
|
local curcontext="$curcontext" ret=1
|
||||||
local -a state line commands
|
local -a state line commands
|
||||||
|
|
||||||
commands=(
|
commands=(
|
||||||
"enable:enable the firewall"
|
"enable:enable the firewall"
|
||||||
"disable:disable the firewall"
|
"disable:disable the firewall"
|
||||||
"default:set default policy"
|
"default:set default policy"
|
||||||
"logging:set logging level"
|
"logging:set logging level"
|
||||||
"allow:add allow rule"
|
"allow:add allow rule"
|
||||||
"deny:add deny rule"
|
"deny:add deny rule"
|
||||||
"reject:add reject rule"
|
"reject:add reject rule"
|
||||||
"limit:add limit rule"
|
"limit:add limit rule"
|
||||||
"delete:delete rule"
|
"delete:delete rule"
|
||||||
"insert:insert rule at position"
|
"insert:insert rule at position"
|
||||||
"route:add route rule"
|
"route:add route rule"
|
||||||
"reload:reload firewall"
|
"reload:reload firewall"
|
||||||
"reset:reset firewall"
|
"reset:reset firewall"
|
||||||
"status:show firewall status"
|
"status:show firewall status"
|
||||||
"show:show firewall report"
|
"show:show firewall report"
|
||||||
"version:display version information"
|
"version:display version information"
|
||||||
"prepend:add rule before all of the same type"
|
"prepend:add rule before all of the same type"
|
||||||
)
|
"app:application profile command"
|
||||||
|
)
|
||||||
|
|
||||||
_arguments -C -s -S -n \
|
_arguments -C -s -S -n \
|
||||||
'(- 1 *)'--version"[display version information]: :->full" \
|
'(- 1 *)'--version"[display version information]: :->full" \
|
||||||
'(- 1 *)'{-h,--help}'[display usage information]: :->full' \
|
'(- 1 *)'{-h,--help}'[display usage information]: :->full' \
|
||||||
'(- 1 *)'--dry-run"[don't modify anything, just show the changes]: :->cmds" \
|
'(- 1 *)'--dry-run"[don't modify anything, just show the changes]: :->cmds" \
|
||||||
'1:cmd:->cmds' \
|
'1:cmd:->cmds' \
|
||||||
'*:: :->args' && ret=0
|
'*:: :->args' && ret=0
|
||||||
|
|
||||||
case "$state" in
|
case "$state" in
|
||||||
(cmds)
|
(cmds)
|
||||||
_describe -t commands 'commands' commands
|
_describe -t commands 'commands' commands
|
||||||
;;
|
;;
|
||||||
(args)
|
(args)
|
||||||
local cmd
|
local cmd
|
||||||
cmd=$words[1]
|
cmd=$words[1]
|
||||||
case "$cmd" in
|
case "$cmd" in
|
||||||
(logging)
|
(logging)
|
||||||
_ufw_logging && ret=0
|
_ufw_logging && ret=0
|
||||||
;;
|
;;
|
||||||
(delete)
|
(delete)
|
||||||
_ufw_delete && ret=0
|
_ufw_delete && ret=0
|
||||||
;;
|
;;
|
||||||
(*)
|
(app)
|
||||||
_default && ret=0
|
_ufw_app && ret=0
|
||||||
;;
|
;;
|
||||||
esac
|
(*)
|
||||||
|
_default && ret=0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
;;
|
;;
|
||||||
(*)
|
(*)
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
_ufw
|
_ufw "$@"
|
||||||
|
|
||||||
|
# Local Variables:
|
||||||
|
# mode: Shell-Script
|
||||||
|
# sh-indentation: 2
|
||||||
|
# indent-tabs-mode: nil
|
||||||
|
# sh-basic-offset: 2
|
||||||
|
# End:
|
||||||
|
# vim: ft=zsh sw=2 ts=2 et
|
||||||
|
|
Loading…
Reference in New Issue