The output of `compopt' in a running completion function is a command where the last word is usually the command for which the compspec was defined.
However, if the current compspec was found by using the basename of the command word, or by invoking default completion, the output will use the typed command word, rather than a command for which a compspec has been defined. $ f() { echo; compopt; } $ complete -r $ complete -F f f $ f ^I compopt +o [...] f $ /bin/f ^I compopt +o [...] /bin/f In fact, the word printed at the end is the same string that is passed to the completion function as $1. I think it would be useful if the compopt output instead used the actual command for the currently running compspec. For example, this would allow a completion function to retrieve its compspec by running `complete -p' with the last word of the `compopt' output. (This patch does not change the value of $1 passed to the completion function.) --- pcomplete.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pcomplete.c b/pcomplete.c index b1c5a371..6e5267a5 100644 --- a/pcomplete.c +++ b/pcomplete.c @@ -1531,7 +1531,7 @@ gen_progcomp_completions (const char *ocmd, const char *cmd, const char *word, oldtxt = pcomp_curtxt; pcomp_curcs = cs; - pcomp_curcmd = cmd; + pcomp_curcmd = ocmd; pcomp_curtxt = word; ret = gen_compspec_completions (cs, cmd, word, start, end, foundp); -- 2.40.1