From ca04327e24793348cb84b7a8494718fe5a4881c9 Mon Sep 17 00:00:00 2001 From: Guilherme Bufolo Date: Sat, 6 Apr 2013 13:47:18 +0200 Subject: Improved bash completion when using tools like '-t clean' --- misc/bash-completion | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/misc/bash-completion b/misc/bash-completion index b40136e..2d6975b 100644 --- a/misc/bash-completion +++ b/misc/bash-completion @@ -18,16 +18,23 @@ _ninja_target() { local cur targets dir line targets_command OPTIND cur="${COMP_WORDS[COMP_CWORD]}" - dir="." - line=$(echo ${COMP_LINE} | cut -d" " -f 2-) - while getopts C: opt "${line[@]}"; do - case $opt in - C) dir="$OPTARG" ;; - esac - done; - targets_command="ninja -C ${dir} -t targets all" - targets=$((${targets_command} 2>/dev/null) | awk -F: '{print $1}') - COMPREPLY=($(compgen -W "$targets" -- "$cur")) - return 0 + + if [[ "$cur" == "--"* ]]; then + # there is currently only one argument that takes -- + COMPREPLY=($(compgen -P '--' -W 'version' -- "${cur:2}")) + else + dir="." + line=$(echo ${COMP_LINE} | cut -d" " -f 2-) + # filter out all non relevant arguments but keep C for dirs + while getopts C:f:j:l:k:nvd:t: opt "${line[@]}"; do + case $opt in + C) dir="$OPTARG" ;; + esac + done; + targets_command="ninja -C ${dir} -t targets all" + targets=$((${targets_command} 2>/dev/null) | awk -F: '{print $1}') + COMPREPLY=($(compgen -W "$targets" -- "$cur")) + fi + return } complete -F _ninja_target ninja -- cgit v0.12