Note: the first argument passed to the registered function is NOT the whole command line as entered by the user, but only the last part, i.e. the part after the last space.
e.g.:
<?php
function my_readline_completion_function($string, $index) {
// If the user is typing:
// mv file.txt directo[TAB]
// then:
// $string = directo
// the $index is the place of the cursor in the line:
// $index = 19;
$array = array(
'ls',
'mv',
'dar',
'exit',
'quit',
);
// Here, I decide not to return filename autocompletion for the first argument (0th argument).
if ($index) {
$ls = `ls`;
$lines = explode("\n", $ls);
foreach ($lines AS $key => $line) {
if (is_dir($line)) {
$lines[$key] .= '/';
}
$array[] = $lines[$key];
}
}
// This will return both our list of functions, and, possibly, a list of files in the current filesystem.
// php will filter itself according to what the user is typing.
return $array;
}
?>