note 91769 modified in function.readline-completion-function by danbrown

From: Date: Thu, 25 Jun 2009 13:03:49 +0000
Subject: note 91769 modified in function.readline-completion-function by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157490@lists.php.net to get a copy of this message
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; } ?> --was-- 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; } ?> P.S. The spam challenges are getting harder and harder: Answer to this simple question (SPAM challenge): zero minus zero? I guess that if you are reading this, it means I got the right answer! http://php.net/manual/en/function.readline-completion-function.php

« previous php.notes (#157490) next »