--- bash-2.05/lib/readline/complete.c.foldfix Wed Feb 14 13:47:18 2001 +++ bash-2.05/lib/readline/complete.c Mon Sep 17 21:16:20 2001 @@ -747,7 +747,7 @@ } /* Find the common prefix of the list of matches, and put it into - matches[0]. */ + match_list[0]. */ static int compute_lcd_of_matches (match_list, matches, text) char **match_list; @@ -803,7 +803,42 @@ else { match_list[0] = xmalloc (low + 1); - strncpy (match_list[0], match_list[1], low); + + /* If we use case folding, try to keep the same case as text */ + if (_rl_completion_case_fold) + { + + if (strlen(text) < low) + { + /* we need a sorted list to get consistent answers */ + qsort (match_list+1, matches, sizeof (char *), + (QSFUNC *)_rl_qsort_string_compare); + + /* find the first entry in match_list with text as prefix */ + for (i = 1; i <= matches; i++) + if (!strncmp(match_list[i], text, strlen (text))) + { + strncpy (match_list[0], match_list[i], low); + break; + } + + /* no casematch, so use the first entry */ + if (i > matches) + strncpy (match_list[0], match_list[1], low); + + } + else + { + /* else just use text */ + strncpy (match_list[0], text, low); + } + + } + else + { + strncpy (match_list[0], match_list[1], low); + } + match_list[0][low] = '\0'; }