From 49a0362c12ddbf26e66237a61cb0eb93c03f2a72 Mon Sep 17 00:00:00 2001 From: Max Nordlund gmail Date: Fri, 14 Jan 2022 13:22:54 +0100 Subject: [PATCH] Fix nmap --script completion It's using GNU specific flags, which doesn't work on BSDs like macOS. Instead this just formats the current time into seconds and then the `math` builtin for calculating the 5 min timeout. --- share/completions/nmap.fish | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/share/completions/nmap.fish b/share/completions/nmap.fish index 61b9842c8..213a9f4d9 100644 --- a/share/completions/nmap.fish +++ b/share/completions/nmap.fish @@ -71,9 +71,12 @@ complete -c nmap -l max-os-tries -d 'Set the maximum number of OS detection trie # NMAP SCRIPTING ENGINE (NSE) complete -c nmap -o sC -d 'Scan: Scripts (default)' function __fish_complete_nmap_script + set -l now (date "+%s") + # cache completion for 5 minutes (`nmap --script-help all` is slow) - if test -z "$__fish_nmap_script_completion_cache" -o (date -d "now - 5min" +"%s") -gt "$__fish_nmap_script_completion_cache_time" - set -g __fish_nmap_script_completion_cache_time (date +"%s") + # must use `math` because of differences between BSD and GNU `date` + if test -z "$__fish_nmap_script_completion_cache" -o (math $now - 5 "*" 60) -gt "$__fish_nmap_script_completion_cache_time" + set -g __fish_nmap_script_completion_cache_time $now set -g __fish_nmap_script_completion_cache "" set -l cmd for l in (nmap --script-help all 2> /dev/null | grep -A2 -B1 Categories: | grep -v '^\\(--\\|Categories:\\|https:\\)')