From af120ab348f2e1a5a39dec035ed9dcf84189a64e Mon Sep 17 00:00:00 2001
From: Biswakalyan Bhuyan <biswa@surgot.in>
Date: Mon, 3 Oct 2022 21:42:20 +0530
Subject: dotfiles

---
 zsh/oh-my-zsh/plugins/ufw/README.md |  18 ++++++
 zsh/oh-my-zsh/plugins/ufw/_ufw      | 115 ++++++++++++++++++++++++++++++++++++
 2 files changed, 133 insertions(+)
 create mode 100644 zsh/oh-my-zsh/plugins/ufw/README.md
 create mode 100644 zsh/oh-my-zsh/plugins/ufw/_ufw

(limited to 'zsh/oh-my-zsh/plugins/ufw')

diff --git a/zsh/oh-my-zsh/plugins/ufw/README.md b/zsh/oh-my-zsh/plugins/ufw/README.md
new file mode 100644
index 0000000..ac377cd
--- /dev/null
+++ b/zsh/oh-my-zsh/plugins/ufw/README.md
@@ -0,0 +1,18 @@
+# UFW plugin
+
+This plugin adds completion for managing everybody's favorite Uncomplicated Firewall (UFW),
+a simple interface for managing iptables. Learn more about [`UFW`](https://wiki.ubuntu.com/UncomplicatedFirewall).
+
+To use it, add ufw to the plugins array of your zshrc file:
+```
+plugins=(... ufw)
+```
+
+Some of the commands include:
+
+* `allow <port>/<optional: protocol>` add an allow rule 
+* `default` set default policy
+* `delete <port>/<optional: protocol>` delete RULE
+* `deny <port>/<optional: protocol>` add deny rule
+* `disable` disables the firewall
+* `enable` enables the firewall
diff --git a/zsh/oh-my-zsh/plugins/ufw/_ufw b/zsh/oh-my-zsh/plugins/ufw/_ufw
new file mode 100644
index 0000000..f5ad033
--- /dev/null
+++ b/zsh/oh-my-zsh/plugins/ufw/_ufw
@@ -0,0 +1,115 @@
+#compdef ufw
+#autoload
+
+typeset -A opt_args
+
+function _ufw_delete_rules {
+  if ufw status &> /dev/null ; then
+    ufw status numbered \
+      | perl -n -e'/\[ +(\d+)\] +([^ ].+)/ && print "\"$1\[$2\]\" "'
+  fi
+}
+
+function _ufw_app_profiles {
+  grep -rhoP "(?<=\[)[^\]]+" /etc/ufw/applications.d/ \
+    | awk '{ print "\""$0"\""}' \
+    | tr '\n' ' '
+}
+
+local -a _1st_arguments
+_1st_arguments=(
+  'allow:add allow rule'
+  'app:Application profile commands'
+  'default:set default policy'
+  'delete:delete RULE'
+  'deny:add deny rule'
+  'disable:disables the firewall'
+  'enable:enables the firewall'
+  'insert:insert RULE at NUM'
+  'limit:add limit rule'
+  'logging:set logging to LEVEL'
+  'reject:add reject rule'
+  'reload:reloads firewall'
+  'reset:reset firewall'
+  'show:show firewall report'
+  'status:show firewall status'
+  'version:display version information'
+)
+
+local context state line curcontext="$curcontext"
+
+_arguments -C \
+  '(--dry-run)--dry-run[dry run]' \
+  '1:: :->cmds' \
+  '2:: :->subcmds' \
+  '3:: :->subsubcmds' \
+&& return 0
+
+local rules
+
+case "$state" in
+  (cmds)
+    _describe -t commands "ufw commands" _1st_arguments
+    return 0
+    ;;
+  (subcmds)
+    case "$line[1]" in
+      (app)
+        _values 'app' \
+          'list[list application profiles]' \
+          'info[show information on PROFILE]' \
+          'update[update PROFILE]' \
+          'default[set default application policy]' \
+        && ret=0
+        ;;
+      (status)
+        _values 'status' \
+          'numbered[show firewall status as numbered list of RULES]' \
+          'verbose[show verbose firewall status]' \
+        && ret=0
+        ;;
+      (logging)
+        _values 'logging' \
+          'on' 'off' 'low' 'medium' 'high' 'full' \
+        && ret=0
+        ;;
+      (default)
+        _values 'default' \
+          'allow' 'deny' 'reject' \
+        && ret=0
+        ;;
+      (show)
+        _values 'show' \
+          'raw' 'builtins' 'before-rules' 'user-rules' 'after-rules' 'logging-rules' 'listening' 'added' \
+        && ret=0
+        ;;
+      (delete)
+        rules="$(_ufw_delete_rules)"
+        if [[ -n "$rules" ]] ; then
+          _values 'delete' \
+            ${(Q)${(z)"$(_ufw_delete_rules)"}} \
+          && ret=0
+        fi
+        ;;
+    esac
+    ;;
+  (subsubcmds)
+    case "$line[1]" in
+      (app)
+        case "$line[2]" in
+          (info|update)
+            _values 'profiles' \
+              ${(Q)${(z)"$(_ufw_app_profiles)"}} \
+            && ret=0
+            ;;
+        esac
+        ;;
+      (default)
+        _values 'default-direction' \
+          'incoming' 'outgoing' \
+        && ret=0
+        ;;
+    esac
+esac
+
+return
-- 
cgit v1.2.3-59-g8ed1b