From f094e78ce3c2ccb21cb17908c9c4272626041435 Mon Sep 17 00:00:00 2001 From: "Emilly M.S." Date: Fri, 15 Mar 2024 22:47:18 -0300 Subject: [PATCH] Completions now work after options --- grimshot-bash-completion.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/grimshot-bash-completion.sh b/grimshot-bash-completion.sh index 0ac8e54..e8a1c72 100644 --- a/grimshot-bash-completion.sh +++ b/grimshot-bash-completion.sh @@ -2,17 +2,27 @@ _grimshot_bash_comp() { local req_target="copy save savecopy" + local first_char=$(cut -c -1 <<< "${COMP_WORDS[1]}") + + local target_pos=3 + local cmd_index=1 + local cmd_pos=2 + if [[ $first_char == "-" ]]; then + target_pos=4 + cmd_index=2 + cmd_pos=3 + fi # Complete options - if [[ ${COMP_WORDS[1]} =~ "-" && ${#COMP_WORDS[@]} -eq 2 ]]; then + if [[ $first_char == "-" && ${#COMP_WORDS[@]} -eq 2 ]]; then COMPREPLY=( $(compgen -W "--notify --cursor --wait" -- "${COMP_WORDS[COMP_CWORD]}") ) # Complete commands - elif [[ ${#COMP_WORDS[@]} -eq 2 ]]; then + elif [[ ${#COMP_WORDS[@]} -eq $cmd_pos ]]; then COMPREPLY=( $(compgen -W "check usage $req_target" -- "${COMP_WORDS[COMP_CWORD]}") ) # Complete targets - elif [[ $req_target =~ "${COMP_WORDS[1]}" && ${#COMP_WORDS[@]} -eq 3 ]]; then + elif [[ $req_target =~ "${COMP_WORDS[$cmd_index]}" && ${#COMP_WORDS[@]} -eq $target_pos ]]; then COMPREPLY=( $(compgen -W "active screen output area window anything" -- "${COMP_WORDS[COMP_CWORD]}") ) fi }