Hello!

I have a completion function where I want the list of completions to
match COMPREPLY exactly. No sorting or deduplicating.

I thought compopt -o nosort would disable both. Turned out that the
deduplication is only disabled for *non-adjacent* entries. Adjacent
duplicates are still folded into one.

Duplicates in this context are not a sign of a mistake, they are all
a valid choice. Which one gets to be used once the command is run is
determined by other options on the command line. Kind of like how the
same argument to -l in gcc can lead to very different outcomes based on
what -L options are supplied, and in what order.  Showing the duplicates
tells the user that there is a choice, and avoids potential confusion.
The function in question deduplicates COMPREPLY, but only if duplicates
are the only remaining items.

The patch below disables the deduplication of adjacent entries too when
-o nosort is used. Do you think this is reasonable? Any downsides?

--- bash-5.3/pcomplete.c        2024-07-09 23:38:54.000000000 +0800
+++ bash-5.3a/pcomplete.c       2026-02-22 20:37:00.272792797 +0800
@@ -1471,8 +1471,10 @@
   if (flags & COPT_NOQUOTE)
     rl_filename_quoting_desired = 1 - nval;
   /* Ditto */
-  if (flags & COPT_NOSORT)
+  if (flags & COPT_NOSORT) {
     rl_sort_completion_matches = 1 - nval;
+    rl_ignore_completion_duplicates = 1 - nval;
+  }
 }
 
 /* Set or unset FLAGS in the options word of the current compspec.

 -- 
 Thanks,
 Georgi


Reply via email to