Speed-up bash target auto-complete.
authorHadi Moshayedi <hadi@moshayedi.net>
Sat, 31 Oct 2015 10:13:33 +0000 (06:13 -0400)
committerHadi Moshayedi <hadi@moshayedi.net>
Sat, 31 Oct 2015 10:13:33 +0000 (06:13 -0400)
These speed-ups include:

* Let compgen do the command substitution. Similar to
  https://lists.gnu.org/archive/html/bug-bash/2012-03/msg00115.html
* Use "cut" instead of "awk" for separating fields.

misc/bash-completion

index 0536760..e604cd4 100644 (file)
@@ -49,9 +49,8 @@ _ninja_target() {
                C) eval dir="$OPTARG" ;;
            esac
        done;
-       targets_command="eval ninja -C \"${dir}\" -t targets all"
-       targets=$(${targets_command} 2>/dev/null | awk -F: '{print $1}')
-       COMPREPLY=($(compgen -W "$targets" -- "$cur"))
+       targets_command="eval ninja -C \"${dir}\" -t targets all 2>/dev/null | cut -d: -f1"
+       COMPREPLY=($(compgen -W '`${targets_command}`' -- "$cur"))
     fi
     return
 }