Skip to content
This repository was archived by the owner on Jul 12, 2020. It is now read-only.

Implemented: Bash autocompletion. #34

Merged
merged 1 commit into from
Sep 16, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/config/autocomplete.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!bash
#
# bash completion support for php-refactoring-browser
#
# Copyright (C) 2013 Tobias Schlitt <toby@php.net>
#
# Code copied and adjusted from https://github.com/KnpLabs/symfony2-autocomplete:
# Copyright (C) 2011 Matthieu Bontemps <matthieu@knplabs.com>
# 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//:}