From 83ea0e56cf045c8a9c1c500a64367898781f453c Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Thu, 15 Jun 2017 17:29:05 -0700 Subject: [PATCH 1/2] [zsh-completion] Fix help message parse bugs and add improvements This fixes a bug where certain tab completions would be met with lots of sed errors. It is also faster since it uses 1 less sed process. Additionally it will also show 'no matches' if there are no matches found for a command completion, instead of showing a suggestion to add 1st level commands on. Before: equo X (no cmds left to add) zsh suggests install, query, remove etc. Now it will properly say there are not more suggestions for most of the $1 terms --- client/equo-completion.zsh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/client/equo-completion.zsh b/client/equo-completion.zsh index 78ab845e0..5076a08ac 100644 --- a/client/equo-completion.zsh +++ b/client/equo-completion.zsh @@ -12,11 +12,22 @@ _equo_get_mirrors() _equo_get_cmds() { - cmds=( ${(f)"$(equo $1 --help | - sed 's/--multifetch/--multifetch can be/' | - sed -r -e '/^(positional|action:)/ {N; d;}' | + # If we return the equo --help text and have a 1st argument + # then that means there is no matching name so return nothing + local help_txt=$(equo $@ --help) + if [[ "$1" && ${help_txt[0,16]} == 'usage: equo [-h]' ]]; then + cmds=( ) + # Otherwise, parse it + else + cmds=( + ${(f)"$( + printf "%s" "$help_txt" | + sed -e 's/--multifetch/--multifetch can be/' \ + -r -e '/^(positional|action:)/ {N; d;}' | grep -P '^ (?!-h||{| )' | - sed -r 's/^ {2,4}(-*[a-zA-z0-9-]+)(, -\w|) +(\w.*)/\1:\3/')"} ) + sed -r 's/^ {2,4}(-*\w+)(, *-\w+)? +(\w.*)/\1:\3/')"} + ) + fi _describe -t commands 'command params' cmds } From 14921ad719473de5493d89b6356170380367a09a Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Thu, 15 Jun 2017 17:41:31 -0700 Subject: [PATCH 2/2] [zsh-completion] Fix completion for equo query list Before no completions would show. Now we remove unneeded code and use the same completion processing for other commands. --- client/equo-completion.zsh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/equo-completion.zsh b/client/equo-completion.zsh index 5076a08ac..9c629d5a1 100644 --- a/client/equo-completion.zsh +++ b/client/equo-completion.zsh @@ -93,8 +93,7 @@ case $state in installed) ;; *) - cmds=( ${(f)"$(equo query list --help |tr "\t" ":" | grep "^::[^:]" | sed 's/^::\([^:\ ]*\)[^:]*:*/\1:/')"} ) - _describe -t commands 'command params' cmds + _equo_get_cmds $line ;; esac ;;