{"id":15808588,"url":"https://github.com/hanneskod/comphlete","last_synced_at":"2025-08-07T20:30:02.351Z","repository":{"id":62514546,"uuid":"204897083","full_name":"hanneskod/comphlete","owner":"hanneskod","description":"Dynamic bash completion from PHP","archived":false,"fork":false,"pushed_at":"2020-02-18T11:50:23.000Z","size":77,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-21T08:44:54.253Z","etag":null,"topics":["autocomplete","complete","php-cli"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hanneskod.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-28T09:35:48.000Z","updated_at":"2023-12-01T07:56:40.000Z","dependencies_parsed_at":"2022-11-02T10:17:15.300Z","dependency_job_id":null,"html_url":"https://github.com/hanneskod/comphlete","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/hanneskod/comphlete","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hanneskod%2Fcomphlete","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hanneskod%2Fcomphlete/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hanneskod%2Fcomphlete/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hanneskod%2Fcomphlete/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hanneskod","download_url":"https://codeload.github.com/hanneskod/comphlete/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hanneskod%2Fcomphlete/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263905739,"owners_count":23527971,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autocomplete","complete","php-cli"],"created_at":"2024-10-05T03:04:13.838Z","updated_at":"2025-07-06T13:04:20.149Z","avatar_url":"https://github.com/hanneskod.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# comphlete\n\n[![Packagist Version](https://img.shields.io/packagist/v/hanneskod/comphlete.svg?style=flat-square)](https://packagist.org/packages/hanneskod/comphlete)\n[![Build Status](https://img.shields.io/travis/hanneskod/comphlete/master.svg?style=flat-square)](https://travis-ci.org/hanneskod/comphlete)\n\nDynamic bash completion from PHP\n\n## Why?\n\nSay you have a cli script to read some data, using comphlete you can\nautocomplete data identifiers directly from the command line. It's both fun and\npowerful. And works well with symfony console apps.\n\n## Installation\n\n```shell\ncomposer require hanneskod/comphlete\n```\n\n## Usage\n\n### With symfony apps\n\nCreate an empty symfony console application (here named `myapp.php`).\n\n```php\n$application = new \\Symfony\\Component\\Console\\Application();\n\n$application-\u003eadd(new \\hanneskod\\comphlete\\Symfony\\ComphleteCommand);\n\n$application-\u003erun();\n```\n\nThis creates a hidden command named `_complete` that handles autocompletion.\n\nTo register autocompletion in your enviroment use (in `.bashrc`)\n\n```shell\nsource $(myapp.php _complete --generate-bash-script --app-name=myapp.php)\n```\n\n\u003e NOTE that the `ComphleteCommand` does not work for single command applications.\n\u003e If your application is a single command app you'll have to revert to the\n\u003e default way of createing suggestions. See below.\n\n### The (not so) hard way\n\nCreate your autocomplete definition in a php script (here named `test.php`).\n\n```php\nnamespace hanneskod\\comphlete;\n\n$definition = (new Definition)\n    // first argument with a fixed set of suggestions\n    -\u003eaddArgument(0, ['foo', 'bar', 'baz'])\n\n    // second argument with a dynamic callback\n    -\u003eaddArgument(1, function () {\n        // load suggestions from database...\n        return ['aa', 'bb'];\n    })\n\n    // simple option\n    -\u003eaddOption('foo')\n\n    // option with suggested values\n    -\u003eaddOption('bar', ['val1', 'val2'])\n;\n\n$completer = new Completer($definition);\n\n$input = (new InputFactory)-\u003ecreateFromArgv($argv);\n\necho Helper::dump($completer-\u003ecomplete($input));\n```\n\nTo load into you environment create a bash script (note that this requires\n`test.php` to be in you `PATH` to work properly).\n\n```shell\nphp bash_load_script_template.php test.php \u003e load.sh\n```\n\nAnd source it (in `.bashrc`)\n\n```shell\nsource load.sh\n```\n\n### Using contexts\n\nA common design pattern is to have an application define a number of commands\nwith their own sets of arguments and options. Comphlete supports this by the use\nof contexts. Here is an app with an `import` and an `export` command.\n\n```php\n$import = (new ContextDefinition('import'))\n    -\u003eaddArgument(1, ['some-argument'])\n;\n\n$export = (new ContextDefinition('export'))\n    -\u003eaddArgument(1, ['another-argument'])\n;\n\n$def = (new ContextContainerDefinition)\n    -\u003eaddContext($import)\n    -\u003eaddContext($export)\n;\n\n$completer = new Completer($def);\n\n$input = (new InputFactory)-\u003ecreateFromArgv($argv);\n\necho Helper::dump($completer-\u003ecomplete($input));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhanneskod%2Fcomphlete","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhanneskod%2Fcomphlete","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhanneskod%2Fcomphlete/lists"}