From b3422db063cbc4f172743ae1c2b91ead0bcb4954 Mon Sep 17 00:00:00 2001 From: Glenn Date: Tue, 26 Dec 2023 22:54:51 +0100 Subject: [PATCH] feat: add completion script for bash --- misc/igmpgen_completion.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 misc/igmpgen_completion.sh diff --git a/misc/igmpgen_completion.sh b/misc/igmpgen_completion.sh new file mode 100644 index 0000000..609ea18 --- /dev/null +++ b/misc/igmpgen_completion.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Function for autocompletion +_igmpgen_completion() { + local cur prev opts igmp_types + COMPREPLY=() # Array variable storing the completions. + cur="${COMP_WORDS[COMP_CWORD]}" # Current word being completed. + prev="${COMP_WORDS[COMP_CWORD-1]}" # Previous word. + + # Options for igmpgen + opts="-i -t -g -s -d -n" + + # Available IGMP packet types + igmp_types="1.query 1.report 1.dvmrp 2.query 2.report 2.leave 3.report" + + case "${prev}" in + -t) + COMPREPLY=( $(compgen -W "${igmp_types}" -- ${cur}) ) + return 0 + ;; + esac + + # If the previous word is an option requiring an argument, don't complete with options + case "${prev}" in + -i | -g | -s | -d | -n) + return 0 + ;; + esac + + # Default completion: suggest igmpgen options + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) +} + +# Attach the completion function to igmpgen command +complete -F _igmpgen_completion igmpgen +