From 5c40b38a05c0e9eb7d26b34cc1347b3af6f84107 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Fri, 10 Jun 2022 12:02:04 -0700 Subject: [PATCH] fix help bash completions so they don't repeat parsers --- jc/shell_completions.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/jc/shell_completions.py b/jc/shell_completions.py index 24b68a7f..ed047291 100644 --- a/jc/shell_completions.py +++ b/jc/shell_completions.py @@ -31,6 +31,26 @@ _jc() fi done + # if jc_help_options and a parser are found anywhere in the line, then no more completions + if + ( + for i in "$${words[@]}"; do + if [[ " $${jc_help_options[*]} " =~ " $${i} " ]]; then + return 0 + fi + done + return 1 + ) && ( + for i in "$${words[@]}"; do + if [[ " $${jc_parsers[*]} " =~ " $${i} " ]]; then + return 0 + fi + done + return 1 + ); then + return 0 + fi + # if jc_help_options are found anywhere in the line, then only complete with parsers for i in "$${words[@]}"; do if [[ " $${jc_help_options[*]} " =~ " $${i} " ]]; then @@ -55,10 +75,10 @@ _jc() fi done - # if a parser arg is found anywhere in the line, only show options + # if a parser arg is found anywhere in the line, only show options and help options for i in "$${words[@]}"; do if [[ " $${jc_parsers[*]} " =~ " $${i} " ]]; then - COMPREPLY=( $$( compgen -W "$${jc_options[*]}" \\ + COMPREPLY=( $$( compgen -W "$${jc_options[*]} $${jc_help_options[*]}" \\ -- "$${cur}" ) ) return 0 fi