From 7d556a09745141ff31a0d40ef55dfc9821cc153a Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Sun, 20 Mar 2016 20:30:21 +0100 Subject: [PATCH] Enable bash completion after --flag= or --flag=abc --- bash_completions.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/bash_completions.go b/bash_completions.go index eea11ee..2e46356 100644 --- a/bash_completions.go +++ b/bash_completions.go @@ -34,7 +34,7 @@ __debug() __my_init_completion() { COMPREPLY=() - _get_comp_words_by_ref cur prev words cword + _get_comp_words_by_ref "$@" cur prev words cword } __index_of_word() @@ -76,6 +76,25 @@ __handle_reply() if [[ $(type -t compopt) = "builtin" ]]; then [[ $COMPREPLY == *= ]] || compopt +o nospace fi + + # complete after --flag=abc + if [[ $cur == *=* ]]; then + if [[ $(type -t compopt) = "builtin" ]]; then + compopt +o nospace + fi + + local index flag + flag="${cur%%=*}" + __index_of_word "${flag}" "${flags_with_completion[@]}" + if [[ ${index} -ge 0 ]]; then + COMPREPLY=() PREFIX="" cur="${cur#*=}" + ${flags_completion[${index}]} + if [ -n "${ZSH_VERSION}" ]; then + # zfs completion needs --flag= prefix + eval COMPREPLY=( "\${COMPREPLY[@]/#/${flag}=}" ) + fi + fi + fi return 0; ;; esac @@ -229,7 +248,7 @@ func postscript(w io.Writer, name string) error { if declare -F _init_completion >/dev/null 2>&1; then _init_completion -s || return else - __my_init_completion || return + __my_init_completion -n "=" || return fi local c=0