downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

readline_info> <readline_clear_history
Last updated: Fri, 06 Nov 2009

view this page in

readline_completion_function

(PHP 4, PHP 5)

readline_completion_functionRegisters a completion function

Description

bool readline_completion_function ( callback $function )

This function registers a completion function. This is the same kind of functionality you'd get if you hit your tab key while using Bash.

Parameters

function

You must supply the name of an existing function which accepts a partial command line and returns an array of possible matches.

Return Values

Returns TRUE on success or FALSE on failure.



readline_info> <readline_clear_history
Last updated: Fri, 06 Nov 2009
 
add a note add a note User Contributed Notes
readline_completion_function
overshoot.tv
25-Jun-2009 07:07
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;
}
?>
david at acz dot org
01-Feb-2005 08:08
This function can simply return an array of all possible matches (regardless of the current user intput) and readline will handle the matching itself.  This is likely to be much faster than attempting to handle partial matches in PHP.
john at weider dot cc
21-Sep-2002 04:32
It seems that the registered function can accept 2 parameters, the first being the partial string, the second a number that when equal to zero indicates that the tab was hit on the first argument on the input. Otherwise it looks like the position within the string is returned.

This is neccessary information for processing shell command line input.

readline_info> <readline_clear_history
Last updated: Fri, 06 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites