I have a PHP command line script which kicks off a job to a job server, with the job name being an argument. The job names are namespaced, such as Foo:Bar_Baz_JobName. Is there a way I could implement auto-completion, like how typing the first few letters of a filename and pressing tab bash completes the file name for you. I know it can be done, because tab-completion works on ubuntu with apt-get, I just don’t know if it can be done in PHP.
Share
Autocompletion is done using the GNU readline library, which apparently is accessible from PHP. Specifically, look at
readline_completion_function. Usage is fairly simple; you callreadline_completion_functionwith one argument, a callback function that handles the completion. The callback function takes the first few letters (basically, whatever you type before pressing TAB) as input and should return an array of possible matches.