From 56f0995ae53afe04d8a3000465cc1a32c0b1afa5 Mon Sep 17 00:00:00 2001 From: PrathmeshSambrekar Date: Fri, 31 Mar 2023 13:01:34 -0700 Subject: [PATCH 1/7] Fixed issue with bash completion --- bash_completion.sh | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/bash_completion.sh b/bash_completion.sh index 0791074cd..d6589aee6 100644 --- a/bash_completion.sh +++ b/bash_completion.sh @@ -128,11 +128,33 @@ _buildtest () { local cur="${COMP_WORDS[COMP_CWORD]}" local prev="${COMP_WORDS[COMP_CWORD-1]}" + local next= + declare -i offset="0" COMPREPLY=() # Array variable storing the possible completions. - next=${COMP_WORDS[1]} + declare -a buildtest_opts=("--color" "--config" "--debug" "--editor" "--help" "--helpcolor" "--logpath" "--loglevel" "--print-log" "--no-color" "--report" "--version" "--view-log" "-c" "-d" "-h" "-l" "-p" "-r" "-V") + + for command in "${COMP_WORDS[@]}" + do + for element in "${buildtest_opts[@]}" + do + + if [[ "$command" == "$element" ]]; then + + if [[ "$command" == "--color" ]] || [[ "$command" == "--config" ]] || [[ "$command" == "-c" ]] || [[ "$command" == "--report" ]] || [[ "$command" == "-r" ]]; + then + ((offset+=2)) + else + ((offset+=1)) + fi + fi + + done + + done + next=${COMP_WORDS[1+offset]} case "$next" in #case "${prev}" in @@ -205,7 +227,7 @@ _buildtest () COMPREPLY=( $( compgen -W "$(_avail_report_formatfields)" -- $cur ) ) return esac - case "$prev" in summary) + case "$prev" in summary|sm) local opts="-d -h --detailed --help" COMPREPLY=( $( compgen -W "${opts}" -- $cur ) ) return @@ -218,7 +240,7 @@ _buildtest () COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) ) # handle completion logic for 'buildtest config ' based on subcommands - case "${COMP_WORDS[COMP_CWORD-2]}" in + case "${COMP_WORDS[2+offset]}" in compilers|co) local opts="--help --json --yaml -h -j -y find test" COMPREPLY=( $( compgen -W "${opts}" -- $cur ) ) @@ -226,7 +248,7 @@ _buildtest () local opts="--detailed --help --modulepath --update -d -h -m -u" COMPREPLY=( $( compgen -W "${opts}" -- $cur ) ) fi - if [[ "${prev}" == "test" ]]; then + if [[ "${prev}" == "test" ]]; then COMPREPLY=( $( compgen -W "$(_avail_compilers)" -- $cur ) ) fi ;; @@ -253,7 +275,7 @@ _buildtest () COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) ) # case statement to handle completion for buildtest inspect [name|id|list] command - case "${COMP_WORDS[2]}" in + case "${COMP_WORDS[2+offset]}" in list|l) local opts="--builder --help --no-header --pager --terse -b -h -n -t" COMPREPLY=( $( compgen -W "${opts}" -- $cur ) );; @@ -292,9 +314,9 @@ _buildtest () COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) ) # switch based on 2nd word 'buildtest buildspec ' - case ${COMP_WORDS[2]} in + case ${COMP_WORDS[2+offset]} in find|f) - case ${COMP_WORDS[3]} in + case ${COMP_WORDS[3+offset]} in # completion for 'buildtest buildspec find invalid' invalid) local opts="--error --help -e -h" @@ -318,7 +340,7 @@ _buildtest () esac ;; summary|sm) - case ${COMP_WORDS[3]} in + case ${COMP_WORDS[3+offset]} in # completion for rest of arguments *) local longopts="--help --pager" @@ -358,7 +380,7 @@ _buildtest () local opts="--breakdown --list --help --terse --no-header -b -h -l -n find" COMPREPLY=( $( compgen -W "${opts}" -- $cur ) ) - case ${COMP_WORDS[3]} in + case ${COMP_WORDS[3+offset]} in find) COMPREPLY=( $( compgen -W "$(_avail_maintainers)" -- $cur ) );; esac @@ -383,7 +405,7 @@ _buildtest () local cmds="--help --pager -h list query" COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) ) - case ${COMP_WORDS[2]} in + case ${COMP_WORDS[2+offset]} in list) local opts="--help --no-header --terse -h -n -t" COMPREPLY=( $( compgen -W "${opts}" -- $cur ) ) From ff5d03f6baae89321a676b399554b13c0c0f352b Mon Sep 17 00:00:00 2001 From: PrathmeshSambrekar Date: Fri, 31 Mar 2023 13:30:37 -0700 Subject: [PATCH 2/7] Shifted a variable --- bash_completion.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bash_completion.sh b/bash_completion.sh index d6589aee6..ab9f0333e 100644 --- a/bash_completion.sh +++ b/bash_completion.sh @@ -128,7 +128,6 @@ _buildtest () { local cur="${COMP_WORDS[COMP_CWORD]}" local prev="${COMP_WORDS[COMP_CWORD-1]}" - local next= declare -i offset="0" COMPREPLY=() # Array variable storing the possible completions. @@ -154,7 +153,7 @@ _buildtest () done - next=${COMP_WORDS[1+offset]} + local next=${COMP_WORDS[1+offset]} case "$next" in #case "${prev}" in From 60065149f89e9c588ae3b0e2af4841dc033c4b7c Mon Sep 17 00:00:00 2001 From: PrathmeshSambrekar Date: Fri, 7 Apr 2023 09:39:44 -0700 Subject: [PATCH 3/7] Added tab completion for the edge cases --loglevel and --editor --- bash_completion.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bash_completion.sh b/bash_completion.sh index ab9f0333e..c25a330ba 100644 --- a/bash_completion.sh +++ b/bash_completion.sh @@ -141,7 +141,7 @@ _buildtest () if [[ "$command" == "$element" ]]; then - if [[ "$command" == "--color" ]] || [[ "$command" == "--config" ]] || [[ "$command" == "-c" ]] || [[ "$command" == "--report" ]] || [[ "$command" == "-r" ]]; + if [[ "$command" == "--color" ]] || [[ "$command" == "--config" ]] || [[ "$command" == "-c" ]] || [[ "$command" == "--report" ]] || [[ "$command" == "-r" ]] || [[ "$command" == "--loglevel" ]] || [[ "$command" == "-l" ]] || [[ "$command" == "--editor" ]]; then ((offset+=2)) else From 7bb46a9597e01d646c4bc59dfb2635acf33422b2 Mon Sep 17 00:00:00 2001 From: PrathmeshSambrekar Date: Tue, 11 Apr 2023 13:12:23 -0700 Subject: [PATCH 4/7] Replaced long if condition with a check in list of values --- bash_completion.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bash_completion.sh b/bash_completion.sh index c25a330ba..f1792584e 100644 --- a/bash_completion.sh +++ b/bash_completion.sh @@ -132,8 +132,10 @@ _buildtest () COMPREPLY=() # Array variable storing the possible completions. - declare -a buildtest_opts=("--color" "--config" "--debug" "--editor" "--help" "--helpcolor" "--logpath" "--loglevel" "--print-log" "--no-color" "--report" "--version" "--view-log" "-c" "-d" "-h" "-l" "-p" "-r" "-V") - + declare -a buildtest_opts=("--color" "--config" "--debug" "--editor" "--help" "--helpcolor" "--logpath" "--loglevel" "--print-log" "--no-color" "--report" "--version" "--view-log" "-c" "-d" "-h" "-l" "-p" "-r" "-V") + + commands=( "--color" "--config" "-c" "--report" "-r" "--loglevel" "-l" "--editor" ) # Array variable storing commands which require an input argument from the user. + for command in "${COMP_WORDS[@]}" do for element in "${buildtest_opts[@]}" @@ -141,7 +143,7 @@ _buildtest () if [[ "$command" == "$element" ]]; then - if [[ "$command" == "--color" ]] || [[ "$command" == "--config" ]] || [[ "$command" == "-c" ]] || [[ "$command" == "--report" ]] || [[ "$command" == "-r" ]] || [[ "$command" == "--loglevel" ]] || [[ "$command" == "-l" ]] || [[ "$command" == "--editor" ]]; + if [[ "${commands[*]}" =~ "$command" ]]; then ((offset+=2)) else From 98787d7c2e895b6868ef6aa462c76f0aec694679 Mon Sep 17 00:00:00 2001 From: PrathmeshSambrekar Date: Tue, 11 Apr 2023 13:20:27 -0700 Subject: [PATCH 5/7] Fixed the failing of CodeFactor check --- bash_completion.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bash_completion.sh b/bash_completion.sh index f1792584e..8d5fd20a3 100644 --- a/bash_completion.sh +++ b/bash_completion.sh @@ -143,7 +143,7 @@ _buildtest () if [[ "$command" == "$element" ]]; then - if [[ "${commands[*]}" =~ "$command" ]]; + if [[ "${commands[*]}" =~ $command ]]; then ((offset+=2)) else From 2656f1eaa5937ad9e3fd66d83d27939d9cfb78ba Mon Sep 17 00:00:00 2001 From: PrathmeshSambrekar Date: Mon, 17 Apr 2023 14:31:02 -0700 Subject: [PATCH 6/7] Adedd bash completion for --editor and renamed variables --- bash_completion.sh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/bash_completion.sh b/bash_completion.sh index 8d5fd20a3..f2e261839 100644 --- a/bash_completion.sh +++ b/bash_completion.sh @@ -134,7 +134,7 @@ _buildtest () declare -a buildtest_opts=("--color" "--config" "--debug" "--editor" "--help" "--helpcolor" "--logpath" "--loglevel" "--print-log" "--no-color" "--report" "--version" "--view-log" "-c" "-d" "-h" "-l" "-p" "-r" "-V") - commands=( "--color" "--config" "-c" "--report" "-r" "--loglevel" "-l" "--editor" ) # Array variable storing commands which require an input argument from the user. + commands_with_input=( "--color" "--config" "-c" "--report" "-r" "--loglevel" "-l" "--editor" ) # Array variable storing commands which require an input argument from the user. for command in "${COMP_WORDS[@]}" do @@ -143,7 +143,7 @@ _buildtest () if [[ "$command" == "$element" ]]; then - if [[ "${commands[*]}" =~ $command ]]; + if [[ "${commands_with_input[*]}" =~ $command ]]; then ((offset+=2)) else @@ -156,6 +156,8 @@ _buildtest () done local next=${COMP_WORDS[1+offset]} + local offset_by_two=2+offset + local offset_by_three=3+offset case "$next" in #case "${prev}" in @@ -241,7 +243,7 @@ _buildtest () COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) ) # handle completion logic for 'buildtest config ' based on subcommands - case "${COMP_WORDS[2+offset]}" in + case "${COMP_WORDS[offset_by_two]}" in compilers|co) local opts="--help --json --yaml -h -j -y find test" COMPREPLY=( $( compgen -W "${opts}" -- $cur ) ) @@ -276,7 +278,7 @@ _buildtest () COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) ) # case statement to handle completion for buildtest inspect [name|id|list] command - case "${COMP_WORDS[2+offset]}" in + case "${COMP_WORDS[offset_by_two]}" in list|l) local opts="--builder --help --no-header --pager --terse -b -h -n -t" COMPREPLY=( $( compgen -W "${opts}" -- $cur ) );; @@ -315,9 +317,9 @@ _buildtest () COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) ) # switch based on 2nd word 'buildtest buildspec ' - case ${COMP_WORDS[2+offset]} in + case ${COMP_WORDS[offset_by_two]} in find|f) - case ${COMP_WORDS[3+offset]} in + case ${COMP_WORDS[offset_by_three]} in # completion for 'buildtest buildspec find invalid' invalid) local opts="--error --help -e -h" @@ -341,7 +343,7 @@ _buildtest () esac ;; summary|sm) - case ${COMP_WORDS[3+offset]} in + case ${COMP_WORDS[offset_by_three]} in # completion for rest of arguments *) local longopts="--help --pager" @@ -381,7 +383,7 @@ _buildtest () local opts="--breakdown --list --help --terse --no-header -b -h -l -n find" COMPREPLY=( $( compgen -W "${opts}" -- $cur ) ) - case ${COMP_WORDS[3+offset]} in + case ${COMP_WORDS[offset_by_three]} in find) COMPREPLY=( $( compgen -W "$(_avail_maintainers)" -- $cur ) );; esac @@ -406,7 +408,7 @@ _buildtest () local cmds="--help --pager -h list query" COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) ) - case ${COMP_WORDS[2+offset]} in + case ${COMP_WORDS[offset_by_two]} in list) local opts="--help --no-header --terse -h -n -t" COMPREPLY=( $( compgen -W "${opts}" -- $cur ) ) @@ -473,6 +475,9 @@ _buildtest () if [[ "${prev}" == "--loglevel" ]] || [[ "${prev}" == "-l" ]]; then COMPREPLY=( $( compgen -W "DEBUG INFO WARNING ERROR CRITICAL" -- $cur ) ) fi + if [[ "${prev}" == "--editor" ]]; then + COMPREPLY=( $( compgen -W "vi vim emacs nano" -- $cur ) ) + fi ;; esac esac From 0bb90438755d10793f6ea08bd6f078ddf4258478 Mon Sep 17 00:00:00 2001 From: PrathmeshSambrekar Date: Tue, 18 Apr 2023 15:51:55 -0700 Subject: [PATCH 7/7] Removed offset_by_two and three variables --- bash_completion.sh | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/bash_completion.sh b/bash_completion.sh index f2e261839..99fd74e49 100644 --- a/bash_completion.sh +++ b/bash_completion.sh @@ -156,9 +156,7 @@ _buildtest () done local next=${COMP_WORDS[1+offset]} - local offset_by_two=2+offset - local offset_by_three=3+offset - + case "$next" in #case "${prev}" in build|bd) @@ -243,7 +241,7 @@ _buildtest () COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) ) # handle completion logic for 'buildtest config ' based on subcommands - case "${COMP_WORDS[offset_by_two]}" in + case "${COMP_WORDS[2+offset]}" in compilers|co) local opts="--help --json --yaml -h -j -y find test" COMPREPLY=( $( compgen -W "${opts}" -- $cur ) ) @@ -278,7 +276,7 @@ _buildtest () COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) ) # case statement to handle completion for buildtest inspect [name|id|list] command - case "${COMP_WORDS[offset_by_two]}" in + case "${COMP_WORDS[2+offset]}" in list|l) local opts="--builder --help --no-header --pager --terse -b -h -n -t" COMPREPLY=( $( compgen -W "${opts}" -- $cur ) );; @@ -317,9 +315,9 @@ _buildtest () COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) ) # switch based on 2nd word 'buildtest buildspec ' - case ${COMP_WORDS[offset_by_two]} in + case ${COMP_WORDS[2+offset]} in find|f) - case ${COMP_WORDS[offset_by_three]} in + case ${COMP_WORDS[3+offset]} in # completion for 'buildtest buildspec find invalid' invalid) local opts="--error --help -e -h" @@ -343,7 +341,7 @@ _buildtest () esac ;; summary|sm) - case ${COMP_WORDS[offset_by_three]} in + case ${COMP_WORDS[3+offset]} in # completion for rest of arguments *) local longopts="--help --pager" @@ -383,7 +381,7 @@ _buildtest () local opts="--breakdown --list --help --terse --no-header -b -h -l -n find" COMPREPLY=( $( compgen -W "${opts}" -- $cur ) ) - case ${COMP_WORDS[offset_by_three]} in + case ${COMP_WORDS[3+offset]} in find) COMPREPLY=( $( compgen -W "$(_avail_maintainers)" -- $cur ) );; esac @@ -408,7 +406,7 @@ _buildtest () local cmds="--help --pager -h list query" COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) ) - case ${COMP_WORDS[offset_by_two]} in + case ${COMP_WORDS[2+offset]} in list) local opts="--help --no-header --terse -h -n -t" COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )