2de926aa109181907def20c21f28d8a5e32b9d85

Author
Thomas Kriechbaumer <Kriechi@users.noreply.github.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

add ufw completion script (#3835)

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/ufw/_ufw b/plugins/ufw/_ufw
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..08f871f35448cd5bbb20d80727689a41b60423c3
  4--- /dev/null
  5+++ b/plugins/ufw/_ufw
  6@@ -0,0 +1,117 @@
  7+#compdef ufw
  8+#autoload
  9+
 10+typeset -A opt_args
 11+
 12+function _ufw_delete_rules {
 13+  if ufw status &> /dev/null ; then
 14+    ufw status numbered \
 15+      | perl -n -e'/\[ +(\d+)\] +([^ ].+)/ && print "\"$1\[$2\]\" "'
 16+  fi
 17+}
 18+
 19+function _ufw_app_profiles {
 20+  grep -rhoP "(?<=\[)[^\]]+" /etc/ufw/applications.d/ \
 21+    | awk '{ print "\""$0"\""}' \
 22+    | tr '\n' ' '
 23+}
 24+
 25+local -a _1st_arguments
 26+_1st_arguments=(
 27+  'allow:add allow rule'
 28+  'app:Application profile commands'
 29+  'default:set default policy'
 30+  'delete:delete RULE'
 31+  'deny:add deny rule'
 32+  'disable:disables the firewall'
 33+  'enable:enables the firewall'
 34+  'insert:insert RULE at NUM'
 35+  'limit:add limit rule'
 36+  'logging:set logging to LEVEL'
 37+  'reject:add reject rule'
 38+  'reload:reloads firewall'
 39+  'reset:reset firewall'
 40+  'show:show firewall report'
 41+  'status:show firewall status'
 42+  'version:display version information'
 43+)
 44+
 45+local context state line curcontext="$curcontext"
 46+
 47+_arguments -C \
 48+  '(--dry-run)--dry-run[dry run]' \
 49+  '1:: :->cmds' \
 50+  '2:: :->subcmds' \
 51+  '3:: :->subsubcmds' \
 52+&& return 0
 53+
 54+echo "DEBUG: $(date)| $state | $line[1] | $line| $word[1]| $word| $CURRENT|" >> log.log
 55+
 56+local rules
 57+
 58+case "$state" in
 59+  (cmds)
 60+    _describe -t commands "ufw commands" _1st_arguments
 61+    return 0
 62+    ;;
 63+  (subcmds)
 64+    case "$line[1]" in
 65+      (app)
 66+        _values 'app' \
 67+          'list[list application profiles]' \
 68+          'info[show information on PROFILE]' \
 69+          'update[update PROFILE]' \
 70+          'default[set default application policy]' \
 71+        && ret=0
 72+        ;;
 73+      (status)
 74+        _values 'status' \
 75+          'numbered[show firewall status as numbered list of RULES]' \
 76+          'verbose[show verbose firewall status]' \
 77+        && ret=0
 78+        ;;
 79+      (logging)
 80+        _values 'logging' \
 81+          'on' 'off' 'low' 'medium' 'high' 'full' \
 82+        && ret=0
 83+        ;;
 84+      (default)
 85+        _values 'default' \
 86+          'allow' 'deny' 'reject' \
 87+        && ret=0
 88+        ;;
 89+      (show)
 90+        _values 'show' \
 91+          'raw' 'builtins' 'before-rules' 'user-rules' 'after-rules' 'logging-rules' 'listening' 'added' \
 92+        && ret=0
 93+        ;;
 94+      (delete)
 95+        rules="$(_ufw_delete_rules)"
 96+        if [[ -n "$rules" ]] ; then
 97+          _values 'delete' \
 98+            ${(Q)${(z)"$(_ufw_delete_rules)"}} \
 99+          && ret=0
100+        fi
101+        ;;
102+    esac
103+    ;;
104+  (subsubcmds)
105+    case "$line[1]" in