From 39f00f92e52b783e7e9e43aac4b4274cc9dee152 Mon Sep 17 00:00:00 2001 From: Tristan Wibberley Date: Tue, 11 Sep 2012 23:24:58 +0100 Subject: [PATCH] make: incremental completion for make with compact display --- completions/make | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/completions/make b/completions/make index 553363e833e..8b36968b638 100644 --- a/completions/make +++ b/completions/make @@ -2,12 +2,27 @@ function _make_target_extract_script() { - local prefix=$(printf "%s\n" "$1" | sed 's/[][\.*^$(){}?+|/]/\\&/g') + local mode="$1" + shift + + local PREFIX="$1" + local PREFIX_PAT=$( printf "%s\n" "$PREFIX" | \ + sed 's/[][\,.*^$(){}?+|/]/\\&/g' ) + local BASENAME=${PREFIX##*/} + local DIRNAME_LEN=$(( ${#PREFIX} - ${#BASENAME} )) + + if [[ $mode == -d ]]; then + # display mode, only output current path component to the next slash + local OUTPUT="\2" + else + # completion mode, output full path to the next slash + local OUTPUT="\1\2" + fi cat </dev/null | \ - sed -n -r -f <(_make_target_extract_script "$cur") )" -- "$cur" ) ) - [[ $COMPREPLY == */ ]] && compopt -o nospace + sed -nrf <(_make_target_extract_script $mode "$cur") ) ) + + if [[ $mode != -d ]]; then + # Completion will occur if there is only one suggestion + # so set options for completion based on the first one + [[ $COMPREPLY == */ ]] && compopt -o nospace + fi fi } &&