small improvement
authorIan Kelling <ian@iankelling.org>
Tue, 14 Apr 2026 23:52:51 +0000 (19:52 -0400)
committerIan Kelling <ian@iankelling.org>
Tue, 14 Apr 2026 23:52:51 +0000 (19:52 -0400)
brc

diff --git a/brc b/brc
index 34543607df55408523183a6006a6430964314778..bdfbaca6c3e8be7edd3d0822f35d484708a559f5 100644 (file)
--- a/brc
+++ b/brc
@@ -4870,10 +4870,11 @@ crypto() {
   cryptsetup luksOpen "$@"
 }
 
-# iptables -I without duplication.
-iptI() { ${*/ -I/ -C/} 2>/dev/null || "$@"; }
-# iptables -A without duplication.
-iptA() { ${*/ -A/ -C/} 2>/dev/null || "$@"; }
+# ipti = iptables idempotent. Swaps -I/-A to -C to check if the rule exists, does not proceed if so.
+# Usage: ipti IPTABLES_ARGS... (where IPTABLES_ARGS includes -I or -A).
+#
+# Note: due to code golf, it expects no spaces in the arguments.
+ipti() { iptables ${*/ -[AI]/ -C/} 2>/dev/null || iptables "$@"; }
 
 
 ### how I calculated lswc-avg (at least for a btrfs filesystem):