Skip to content

Commit

Permalink
Completions now work after options
Browse files Browse the repository at this point in the history
  • Loading branch information
em-s-h committed Mar 16, 2024
1 parent 7915870 commit f094e78
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions grimshot-bash-completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit f094e78

Please sign in to comment.