From cc818d74e12d348d7c1b7ed2be47aee2c1e97759 Mon Sep 17 00:00:00 2001 From: Tobias Schlitt Date: Mon, 16 Sep 2013 09:32:37 +0200 Subject: [PATCH] Implemented: Bash autocompletion. --- src/config/autocomplete.bash | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/config/autocomplete.bash diff --git a/src/config/autocomplete.bash b/src/config/autocomplete.bash new file mode 100644 index 0000000..2cb0818 --- /dev/null +++ b/src/config/autocomplete.bash @@ -0,0 +1,34 @@ +#!bash +# +# bash completion support for php-refactoring-browser +# +# Copyright (C) 2013 Tobias Schlitt +# +# Code copied and adjusted from https://github.com/KnpLabs/symfony2-autocomplete: +# Copyright (C) 2011 Matthieu Bontemps +# Distributed under the GNU General Public License, version 2.0. + +_console() +{ + local cur prev cmd + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + cmd="${COMP_WORDS[0]}" + PHP='$ret = shell_exec($argv[1] . " --no-debug --env=prod"); + +$comps = ""; +$ret = preg_replace("/^.*Available commands:\n/s", "", $ret); +if (preg_match_all("@^ ([^ ]+) @m", $ret, $m)) { + $comps = $m[1]; +} + +echo implode("\n", $comps); +' + possible=$($(which php) -r "$PHP" $COMP_WORDS); + COMPREPLY=( $(compgen -W "${possible}" -- ${cur}) ) + return 0 +} + +complete -F _console refactor +COMP_WORDBREAKS=${COMP_WORDBREAKS//:}