4 namespace Stecman\Component\Symfony\Console\BashCompletion;
6 class EnvironmentCompletionContext extends CompletionContext
9 * Set up completion context from the environment variables set by the parent shell
11 public function __construct()
13 $this->commandLine = getenv('CMDLINE_CONTENTS');
14 $this->charIndex = intval(getenv('CMDLINE_CURSOR_INDEX'));
16 if ($this->commandLine === false) {
17 $message = 'Failed to configure from environment; Environment var CMDLINE_CONTENTS not set.';
19 if (getenv('COMP_LINE')) {
20 $message .= "\n\nYou appear to be attempting completion using an out-dated hook. If you've just updated,"
21 . " you probably need to reinitialise the completion shell hook by reloading your shell"
22 . " profile or starting a new shell session. If you are using a hard-coded (rather than generated)"
23 . " hook, you will need to update that function with the new environment variable names."
24 . "\n\nSee here for details: https://github.com/stecman/symfony-console-completion/issues/31";
27 throw new \RuntimeException($message);
32 * Use the word break characters set by the parent shell.
34 * @throws \RuntimeException
36 public function useWordBreaksFromEnvironment()
38 $breaks = getenv('CMDLINE_WORDBREAKS');
41 throw new \RuntimeException('Failed to read word breaks from environment; Environment var CMDLINE_WORDBREAKS not set');
44 $this->wordBreaks = $breaks;