summaryrefslogtreecommitdiffstats
path: root/misc/bash-completion
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2014-04-30 19:10:54 (GMT)
committerNico Weber <nicolasweber@gmx.de>2014-04-30 19:10:54 (GMT)
commit6c9a54649d4eec45f58e117612a34a2c214a0214 (patch)
tree5131e685fd803571a17da316bd1237066abad563 /misc/bash-completion
parent01ae9ac2583afe263055eed75ca57f2045430a7d (diff)
parentb1d4668260ef142837c76c6ca95c32e1a43d4aef (diff)
downloadNinja-6c9a54649d4eec45f58e117612a34a2c214a0214.zip
Ninja-6c9a54649d4eec45f58e117612a34a2c214a0214.tar.gz
Ninja-6c9a54649d4eec45f58e117612a34a2c214a0214.tar.bz2
Merge pull request #748 from nocnokneo/bash-completion-for-f-and-C
Support completion of arguments to -f and -C options
Diffstat (limited to 'misc/bash-completion')
-rw-r--r--misc/bash-completion23
1 files changed, 20 insertions, 3 deletions
diff --git a/misc/bash-completion b/misc/bash-completion
index 0ca5235..6edf4df 100644
--- a/misc/bash-completion
+++ b/misc/bash-completion
@@ -16,8 +16,25 @@
# . path/to/ninja/misc/bash-completion
_ninja_target() {
- local cur targets dir line targets_command OPTIND
- cur="${COMP_WORDS[COMP_CWORD]}"
+ local cur prev targets dir line targets_command OPTIND
+
+ # When available, use bash_completion to:
+ # 1) Complete words when the cursor is in the middle of the word
+ # 2) Complete paths with files or directories, as appropriate
+ if _get_comp_words_by_ref cur prev &>/dev/null ; then
+ case $prev in
+ -f)
+ _filedir
+ return 0
+ ;;
+ -C)
+ _filedir -d
+ return 0
+ ;;
+ esac
+ else
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ fi
if [[ "$cur" == "--"* ]]; then
# there is currently only one argument that takes --
@@ -26,7 +43,7 @@ _ninja_target() {
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
+ while getopts :C:f:j:l:k:nvd:t: opt $line; do
case $opt in
# eval for tilde expansion
C) eval dir="$OPTARG" ;;