Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: completion for compilers (cc, gcc...) and -o

On Thu, Apr 30, 2020 at 1:52 AM Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> The -o option is currently handled by
>   '-o:output file:_files -g "^*.(c|h|cc|C|cxx)(-.)"'
> I wonder whether .i files (preprocessed files, e.g. for bug reports)
> should be excluded too.
> Moreover, if I have a C source "myprogram.c", I generally want the
> output file (program name) to be "myprogram", or if I need several
> versions (e.g. because I test several options [...]
>   cc -o my[TAB]
> I'd like the "myprogram" to be taken into account.

That seems pretty simple:

zstyle :completion::complete:gcc:option-o-1: file-patterns \
    "^*.(c|h|cc|C|cxx|i)(-.) *.(c|cc|C|cxx)(N\:r)"

Interesting tidbit, you have to backslash the colon there because
_files is parsing this in pattern:tag format, and it's not clever
about parens.

If we think this is useful enough to fold in to the default (pardon
likely line wrapping by gmail):

diff --git a/Completion/Unix/Command/_gcc b/Completion/Unix/Command/_gcc
index 9ec09200e..7437b96c0 100644
--- a/Completion/Unix/Command/_gcc
+++ b/Completion/Unix/Command/_gcc
@@ -390,7 +390,7 @@ languages=(
 # generic options (from --help)
   '-###[print commands to run this compilation]'
-  '-o:output file:_files -g "^*.(c|h|cc|C|cxx)(-.)"'
+  '-o:output file:_files -g "^*.(c|h|cc|C|cxx|i)(-.) *.(c|cc|C|cxx)(N\:r)"'
   '-x[Specify the language of the following input files]:input file
   '+e-:virtual function definitions in classes:((0\:only\ interface
1\:generate\ code))'

Messages sorted by: Reverse Date, Date, Thread, Author