From e6c67528e87f2a0899a3edb5e77432d8ec1aceb9 Mon Sep 17 00:00:00 2001 From: Tommy Nyquist Date: Tue, 30 Oct 2012 15:28:02 -0700 Subject: Add support for reading directory for bash completion. Currently ninja bash completion only works in the directory where the build.ninja files is located. This adds support for using the -C argument to ninja. --- misc/bash-completion | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/misc/bash-completion b/misc/bash-completion index ac4d051..b40136e 100644 --- a/misc/bash-completion +++ b/misc/bash-completion @@ -16,9 +16,17 @@ # . path/to/ninja/misc/bash-completion _ninja_target() { - local cur targets + local cur targets dir line targets_command OPTIND cur="${COMP_WORDS[COMP_CWORD]}" - targets=$((ninja -t targets all 2>/dev/null) | awk -F: '{print $1}') + 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 } -- cgit v0.12