From 84e01e1a804594bc7859b09dcf9233139e3c1be2 Mon Sep 17 00:00:00 2001 From: Bernd Schatz Date: Sun, 29 Mar 2020 19:46:07 +0200 Subject: [PATCH 1/3] ignore vi backup files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index c948f71..5fe8653 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ bin/* lib/* . + +# vi backup files +*~ From 055bc28640c8b36e0b9a601705633c1f33308cf2 Mon Sep 17 00:00:00 2001 From: Bernd Schatz Date: Sun, 29 Mar 2020 19:47:02 +0200 Subject: [PATCH 2/3] ADDED: bash completion --- contrib/completion/g810-led-completion.bash | 115 ++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 contrib/completion/g810-led-completion.bash diff --git a/contrib/completion/g810-led-completion.bash b/contrib/completion/g810-led-completion.bash new file mode 100644 index 0000000..4731d90 --- /dev/null +++ b/contrib/completion/g810-led-completion.bash @@ -0,0 +1,115 @@ +#/usr/bin/env bash + +# OPTIONS +# ####### +g810_device_options="-dv -dp -ds -tuk" +g810_tuk_option="-tuk" +g810_tuk_options="1 2 3" +g810_options="$g810_device_options g810_tuk_option" + +# COMMANDS +# ######## + +# effects +effects_command="-fx" +effects="color breathing cycle waves hwave vwave cwave" +effects_target="all keys logo" + +# startup mode +startup_mode_command="--startup-mode" +startup_modes="wave color" + +# keygroup commands +key_group_commands="-g -gn" +key_groups="logo indicators fkeys gkeys modifiers multimedia arrows numeric functions keys" + +# g810 commands and options +simple_long_commands="--list-keyboards --print-device --help --help-keys --help-effects --help-samples" + +# ALL +# ######## +all="-a -k -an -kn -c $startup_mode_command $simple_long_commands $g810_options $key_group_commands" + + + +_g810-led_completions() +{ + # ignore already typed in g810 options + # TODO check for parameter, and avoid duplicated options + # ###################################################### + local i=1 + while [[ $g810_options =~ ${COMP_WORDS[i]} && ${COMP_CWORD} -gt $i ]] + do + ((i++)) + done + + # check for simple long commands, that dont have parameters + # ######################################################### + local contains=0 + local exactmatch=0 + local opt + for opt in $simple_long_commands + do + if [[ $opt =~ "${COMP_WORDS[i]}" ]]; then let contains=contains+1; fi + if [[ $opt == "${COMP_WORDS[i]}" ]]; then let exactmatch=exactmatch+1; fi + done + if [[ $contains -eq 1 && $exactmatch -eq 1 ]]; then return; fi; + + # long commands with parameter + # ############################ + + # --> startup mode + if [[ $startup_mode_command == "${COMP_WORDS[i]}" ]] + then + ((i++)) + if [[ " $startup_modes " =~ " ${COMP_WORDS[i]} " ]] + then + return; + else + COMPREPLY=($(compgen -W "$startup_modes" -- ${COMP_WORDS[i]})) + return + fi + fi + + # --> effects + if [[ $effects_command == "${COMP_WORDS[i]}" ]] + then + ((i++)) + if [[ " $effects " =~ " ${COMP_WORDS[i]} " ]] + then + ((i++)) + if [[ " $effects_target " =~ " ${COMP_WORDS[i]} " ]] + then + return + else + COMPREPLY=($(compgen -W "$string" -- "${COMP_WORDS[i]}" )) + return + fi + else + COMPREPLY=($(compgen -W "$effects" -- "${COMP_WORDS[i]}" )) + return + fi + fi + + # commands with keygroups + # ####################### + if [[ " $key_group_commands " =~ " ${COMP_WORDS[i]} " ]] + then + ((i++)) + if [[ " $key_groups " =~ " ${COMP_WORDS[i]} " ]] + then + return + else + COMPREPLY=($(compgen -W "$key_groups" -- ${COMP_WORDS[i]})) + return + fi + fi + + + # complete + # ######## + COMPREPLY=($(compgen -W "$all" -- ${COMP_WORDS[i]})) + return +} + +complete -F _g810-led_completions g810-led From 3b49c8ab815b5d256d14696dd9baa37a7d8d65c1 Mon Sep 17 00:00:00 2001 From: Bernd Schatz Date: Sun, 29 Mar 2020 19:51:38 +0200 Subject: [PATCH 3/3] fixed some comments --- contrib/completion/g810-led-completion.bash | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/contrib/completion/g810-led-completion.bash b/contrib/completion/g810-led-completion.bash index 4731d90..07d80ac 100644 --- a/contrib/completion/g810-led-completion.bash +++ b/contrib/completion/g810-led-completion.bash @@ -4,7 +4,7 @@ # ####### g810_device_options="-dv -dp -ds -tuk" g810_tuk_option="-tuk" -g810_tuk_options="1 2 3" +g810_tuk_options="1 2 3" # yet not used g810_options="$g810_device_options g810_tuk_option" # COMMANDS @@ -55,9 +55,6 @@ _g810-led_completions() done if [[ $contains -eq 1 && $exactmatch -eq 1 ]]; then return; fi; - # long commands with parameter - # ############################ - # --> startup mode if [[ $startup_mode_command == "${COMP_WORDS[i]}" ]] then @@ -92,7 +89,6 @@ _g810-led_completions() fi # commands with keygroups - # ####################### if [[ " $key_group_commands " =~ " ${COMP_WORDS[i]} " ]] then ((i++))