PHPackages                             hanneskod/comphlete - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. hanneskod/comphlete

ActiveLibrary

hanneskod/comphlete
===================

Dynamic bash completion from PHP

1.0.0-beta6(6y ago)3127UnlicensePHPPHP &gt;=7

Since Sep 10Pushed 6y ago1 watchersCompare

[ Source](https://github.com/hanneskod/comphlete)[ Packagist](https://packagist.org/packages/hanneskod/comphlete)[ Docs](https://github.com/hanneskod/comphlete)[ RSS](/packages/hanneskod-comphlete/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (7)Used By (0)

comphlete
=========

[](#comphlete)

[![Packagist Version](https://camo.githubusercontent.com/bee97b6b6e09d8d8a2b45da2e63e748d159b4be741dba34517016a6efc8d5ff5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68616e6e65736b6f642f636f6d70686c6574652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hanneskod/comphlete)[![Build Status](https://camo.githubusercontent.com/8d793765835cf40fed616ca23eb0486d570d667d1b259dbf79d160dd753f4683/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f68616e6e65736b6f642f636f6d70686c6574652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/hanneskod/comphlete)

Dynamic bash completion from PHP

Why?
----

[](#why)

Say you have a cli script to read some data, using comphlete you can autocomplete data identifiers directly from the command line. It's both fun and powerful. And works well with symfony console apps.

Installation
------------

[](#installation)

```
composer require hanneskod/comphlete
```

Usage
-----

[](#usage)

### With symfony apps

[](#with-symfony-apps)

Create an empty symfony console application (here named `myapp.php`).

```
$application = new \Symfony\Component\Console\Application();

$application->add(new \hanneskod\comphlete\Symfony\ComphleteCommand);

$application->run();
```

This creates a hidden command named `_complete` that handles autocompletion.

To register autocompletion in your enviroment use (in `.bashrc`)

```
source $(myapp.php _complete --generate-bash-script --app-name=myapp.php)
```

> NOTE that the `ComphleteCommand` does not work for single command applications. If your application is a single command app you'll have to revert to the default way of createing suggestions. See below.

### The (not so) hard way

[](#the-not-so-hard-way)

Create your autocomplete definition in a php script (here named `test.php`).

```
namespace hanneskod\comphlete;

$definition = (new Definition)
    // first argument with a fixed set of suggestions
    ->addArgument(0, ['foo', 'bar', 'baz'])

    // second argument with a dynamic callback
    ->addArgument(1, function () {
        // load suggestions from database...
        return ['aa', 'bb'];
    })

    // simple option
    ->addOption('foo')

    // option with suggested values
    ->addOption('bar', ['val1', 'val2'])
;

$completer = new Completer($definition);

$input = (new InputFactory)->createFromArgv($argv);

echo Helper::dump($completer->complete($input));
```

To load into you environment create a bash script (note that this requires `test.php` to be in you `PATH` to work properly).

```
php bash_load_script_template.php test.php > load.sh
```

And source it (in `.bashrc`)

```
source load.sh
```

### Using contexts

[](#using-contexts)

A common design pattern is to have an application define a number of commands with their own sets of arguments and options. Comphlete supports this by the use of contexts. Here is an app with an `import` and an `export` command.

```
$import = (new ContextDefinition('import'))
    ->addArgument(1, ['some-argument'])
;

$export = (new ContextDefinition('export'))
    ->addArgument(1, ['another-argument'])
;

$def = (new ContextContainerDefinition)
    ->addContext($import)
    ->addContext($export)
;

$completer = new Completer($def);

$input = (new InputFactory)->createFromArgv($argv);

echo Helper::dump($completer->complete($input));
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~32 days

Recently: every ~40 days

Total

6

Last Release

2272d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b0af6567c7f4f5518a422192675445464fdcf18acbc9459b3205da9fd446f8d0?d=identicon)[hanneskod](/maintainers/hanneskod)

---

Top Contributors

[![hanneskod](https://avatars.githubusercontent.com/u/1369274?v=4)](https://github.com/hanneskod "hanneskod (20 commits)")

---

Tags

autocompletecompletephp-cliautocompletecomplete

### Embed Badge

![Health badge](/badges/hanneskod-comphlete/health.svg)

```
[![Health](https://phpackages.com/badges/hanneskod-comphlete/health.svg)](https://phpackages.com/packages/hanneskod-comphlete)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M681](/packages/barryvdh-laravel-ide-helper)[twitter/typeahead.js

fast and fully-featured autocomplete library

16.5k209.7k4](/packages/twitter-typeaheadjs)[jetbrains/phpstorm-stubs

PHP runtime &amp; extensions header files for PhpStorm

1.4k27.7M68](/packages/jetbrains-phpstorm-stubs)[clue/stdio-react

Async, event-driven console input &amp; output (STDIN, STDOUT) for truly interactive CLI applications, built on top of ReactPHP

19810.2M27](/packages/clue-stdio-react)[tetranz/select2entity-bundle

A Symfony bundle that integrates Select2 as a drop-in replacement for a standard entity field on a Symfony form.

2172.9M15](/packages/tetranz-select2entity-bundle)[phalcon/ide-stubs

The most complete Phalcon Framework IDE stubs library which enables autocompletion in modern IDEs.

1623.1M121](/packages/phalcon-ide-stubs)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
