From 348e683cebe4ddada6d9b11c2581bfeacba8d458 Mon Sep 17 00:00:00 2001 From: Shengjing Zhu Date: Tue, 11 Feb 2020 19:53:17 +0800 Subject: [PATCH] Fix zsh autocomplete script Fix completion when argument startswith `-` Merged in upstream https://github.com/urfave/cli/pull/1062 Signed-off-by: Shengjing Zhu --- contrib/autocomplete/ctr | 2 +- contrib/autocomplete/zsh_autocomplete | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) mode change 100755 => 100644 contrib/autocomplete/ctr diff --git a/contrib/autocomplete/ctr b/contrib/autocomplete/ctr old mode 100755 new mode 100644 index a6fde5344f30..051c88056cf8 --- a/contrib/autocomplete/ctr +++ b/contrib/autocomplete/ctr @@ -1,5 +1,5 @@ #! /bin/bash -## This file is a direct copy of https://github.com/urfave/cli/blob/a221e662f14fd7404302444a5c4293409a401210/autocomplete/bash_autocomplete +## This file is a direct copy of https://github.com/urfave/cli/blob/d04c0883fcc8860836ab30ade0fd29afa194ab23/autocomplete/bash_autocomplete : ${PROG:=$(basename ${BASH_SOURCE})} diff --git a/contrib/autocomplete/zsh_autocomplete b/contrib/autocomplete/zsh_autocomplete index a71222a6842e..61af91b00776 100644 --- a/contrib/autocomplete/zsh_autocomplete +++ b/contrib/autocomplete/zsh_autocomplete @@ -1,13 +1,21 @@ #compdef ctr -# This file is a direct copy of https://github.com/urfave/cli/blob/a221e662f14fd7404302444a5c4293409a401210/autocomplete/zsh_autocomplete +# This file is a direct copy of https://github.com/urfave/cli/blob/d04c0883fcc8860836ab30ade0fd29afa194ab23/autocomplete/zsh_autocomplete # With $PROG changed to ctr _cli_zsh_autocomplete() { local -a opts - opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}") + local cur + cur=${words[-1]} + if [[ "$cur" == "-"* ]]; then + opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}") + else + opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}") + fi - _describe 'values' opts + if [[ "${opts[1]}" != "" ]]; then + _describe 'values' opts + fi return }