From b6a97e9361df6e20117101d582f6e70265d40d96 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Sat, 30 Apr 2022 01:53:06 -0400 Subject: [PATCH] subcommand bash completeion for gui and plugin Signed-off-by: Mabel Zhang --- etc/ign.bash_completion.sh | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/etc/ign.bash_completion.sh b/etc/ign.bash_completion.sh index 94c1872..6975520 100644 --- a/etc/ign.bash_completion.sh +++ b/etc/ign.bash_completion.sh @@ -1,14 +1,21 @@ +#!/usr/bin/env bash + # ign bash completion function _ign { local prev cur cmd opts local ign="$1" - COMPREPLY=() cur="$2" prev="$3" - # searching for the command + # Return value + COMPREPLY=() + + # Look for the first command that is not an option (-*) + # COMP_WORDS: array of words in current command line COMP_LINE + # COMP_CWORD: index of word containing current cursur location + # COMP_LINE: line entered so far for ((i=1; $i<=$COMP_CWORD; i++)); do if [[ ${COMP_WORDS[i]} != -* ]]; then cmd="${COMP_WORDS[i]}" @@ -16,16 +23,29 @@ function _ign fi done + # On a word after top-level command ign. It may be an option (-*) if [[ "$cur" == -* ]] || [[ "$prev" != "ign" ]]; then + # Subcommand is help if [[ "$cmd" == "help" ]]; then opts=$(ign --commands) + + # Subcommand is a library name or an option (-*) else - COMPREPLY=($(compgen -f -- "${COMP_WORDS[${COMP_CWORD}]}" )) - complete -o filenames -o nospace -F "_ign" "ign" - return + # Complete subcommands + case "$cmd" in + gui) + _ign_gui + return + ;; + plugin) + _ign_plugin + return + ;; + esac fi + # on first word, top-level command (ign) else opts="$(ign --commands) help" fi