commit 9c4c7682443c31bab35ea6d1942fb242397d9f4e Author: Raphaƫl Droz Date: Sat Jun 25 22:55:11 2011 +0200 Colored completion, bugfix (8/6). When a filename completion needs $PATH traversal (like the completion of a command name), don't hide the absolute path to readline. Matches won't be considered as orphan links anymore when trying to complete a command name. diff --git a/bashline.c b/bashline.c index 692b912..a88fb14 100644 --- a/bashline.c +++ b/bashline.c @@ -1453,6 +1453,10 @@ bash_default_completion (text, start, end, qc, compflags) matches = (char **)NULL; + /* the "command_word_completion_function" callback may change this value + in case we use colored filenames completion. */ + rl_executable_completion_desired = 0; + /* New posix-style command substitution or variable name? */ if (!matches && *text == '$') { @@ -1899,12 +1903,20 @@ globword: bash execution code won't find executables in directories which appear in directories in $PATH when they're specified using relative pathnames. */ - if (match && (searching_path ? executable_file (val) : executable_or_directory (val))) + int is_executable_file = 0; + if (match && (searching_path ? ( is_executable_file = executable_file (val) ) : executable_or_directory (val))) #endif { - free (val); - val = ""; /* So it won't be NULL. */ - return (temp); + if(is_executable_file) { + rl_executable_completion_desired = 1; + free (temp); + return val; + } + else { + free (val); + val = ""; /* So it won't be NULL. */ + return (temp); + } } else { diff --git a/lib/readline/complete.c b/lib/readline/complete.c index 661a5fa..f921d56 100644 --- a/lib/readline/complete.c +++ b/lib/readline/complete.c @@ -317,6 +317,15 @@ int rl_ignore_completion_duplicates = 1; within a completion entry finder function. */ int rl_filename_completion_desired = 0; +/* Non-zero means that at least one of the results of the matches is + an absolute path. This is ALWAYS zero on entry. + If it is set to a non-zero value the lower common denominator will + not be computed. + The matches should expect to be processed by printable_part(). + print_filename() will receive a correct full_pathname parameter. +*/ +int rl_executable_completion_desired = 0; + /* Non-zero means that the results of the matches are to be quoted using double quotes (or an application-specific quoting mechanism) if the filename contains any characters in rl_filename_quote_chars. This is @@ -2077,8 +2086,21 @@ rl_completion_matches (text, entry_function) /* If there were any matches, then look through them finding out the lowest common denominator. That then becomes match_list[0]. */ - if (matches) - compute_lcd_of_matches (match_list, matches, text); + if (matches) { + /* ... except if we are doing filename completion and entry_function() + returned one or more absolute path(s). + The lowest common denominator would not be useful so we + keep the hint_text as-is. + printable_part() will strip the directory name later. + Duplicates will not be removed. + */ + if( rl_executable_completion_desired == 1) { + match_list[0] = (char *)xmalloc (strlen (text) + 1); + strcpy (match_list[0], text); + } + else + compute_lcd_of_matches (match_list, matches, text); + } else /* There were no matches. */ { xfree (match_list); diff --git a/lib/readline/readline.h b/lib/readline/readline.h index dc8b29a..b7ba6c8 100644 --- a/lib/readline/readline.h +++ b/lib/readline/readline.h @@ -747,6 +747,15 @@ extern rl_compdisp_func_t *rl_completion_display_matches_hook; within a completion entry finder function. */ extern int rl_filename_completion_desired; +/* Non-zero means that at least one of the results of the matches is + an absolute path. This is ALWAYS zero on entry. + If it is set to a non-zero value the lower common denominator will + not be computed. + The matches should expect to be processed by printable_part(). + print_filename() will receive a correct full_pathname parameter. +*/ +extern int rl_executable_completion_desired; + /* Non-zero means that the results of the matches are to be quoted using double quotes (or an application-specific quoting mechanism) if the filename contains any characters in rl_word_break_chars. This is