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.
This commit is contained in:
Max Nordlund gmail 2022-01-14 13:22:54 +01:00 committed by Johannes Altmanninger
parent 04a905961d
commit 49a0362c12

View File

@ -71,9 +71,12 @@ complete -c nmap -l max-os-tries -d 'Set the maximum number of OS detection trie
# NMAP SCRIPTING ENGINE (NSE) # NMAP SCRIPTING ENGINE (NSE)
complete -c nmap -o sC -d 'Scan: Scripts (default)' complete -c nmap -o sC -d 'Scan: Scripts (default)'
function __fish_complete_nmap_script function __fish_complete_nmap_script
set -l now (date "+%s")
# cache completion for 5 minutes (`nmap --script-help all` is slow) # 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" # must use `math` because of differences between BSD and GNU `date`
set -g __fish_nmap_script_completion_cache_time (date +"%s") 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 -g __fish_nmap_script_completion_cache ""
set -l cmd set -l cmd
for l in (nmap --script-help all 2> /dev/null | grep -A2 -B1 Categories: | grep -v '^\\(--\\|Categories:\\|https:\\)') for l in (nmap --script-help all 2> /dev/null | grep -A2 -B1 Categories: | grep -v '^\\(--\\|Categories:\\|https:\\)')