Linguist: Associate or disassociate multiple languages with a file extension

Created on 23 Sep 2018  路  9Comments  路  Source: github/linguist

Is it possible to associate or disassociate multiple languages with a file extension?

I can write something like:

*.hpp linguist-language=c++

to associate the C++ programming language with .hpp file extensions inside the .gitattributes. Unfortunately, 3th party libraries are less consistent. .h files can be both C, C++ and Objective C header files. Is there a way to exclude the latter (Objective C) without excluding certain .h files?

Most helpful comment

Ah, sorry. It looks like the correct syntax is:

fmt/**/*.h linguis-language=C++

I tried it on your repository locally and got the following results:

$ bundle exec github-linguist ../MAGE/
81.28%  C++
10.41%  C
8.31%   HLSL

Full results are here.

All 9 comments

You can match on any file path:

$ cat .gitattributes
path/to/cpp/code/*.h linguist-language=C
path/to/c/code/*.h linguist-language=C++

Closed the issue a bit too fast :-)
Should these paths be relative to the root directory or the directory containing the .gitattributes file?
I tried both approaches and obtained no visible changes.

Hm, I think you need to use ** to mean "any file, in any directory." So you'd use:

$ cat .gitattributes
fmt/**.h linguist-language=C++

Thanks, I am going to give this a try.

@matt77hias Did it solve your issue?

Unfortunately nothing happened. I thought to wait a couple of days to let the workers/crawlers do the job, but everything is status quo. For example: Objective C is still recognized.

Ah, sorry. It looks like the correct syntax is:

fmt/**/*.h linguis-language=C++

I tried it on your repository locally and got the following results:

$ bundle exec github-linguist ../MAGE/
81.28%  C++
10.41%  C
8.31%   HLSL

Full results are here.

@pchaigno That did the job! Thanks.

The language header on the main page is now correct. There are, however, still some C and Objective-C mismatches on the search page (which did not change (yet?)), but I presume these will be updated eventually?

They should update later. Unfortunately, we have a lot of reports of discrepancies between the statistics and the search results, so if they don't update, please contact GitHub support.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TimothyGu picture TimothyGu  路  5Comments

philiparvidsson picture philiparvidsson  路  4Comments

oldmud0 picture oldmud0  路  6Comments

haskellcamargo picture haskellcamargo  路  3Comments

etc0de picture etc0de  路  5Comments