I am using Google Chrome, and I want to open
.cpp files as text in the browser itself. Is there any way to do that?
I'm afraid this isn't possible. As the fies are attachments in a Gmail message, there would have to a a viewer in the Gmail web application to view them. It doesn't have a viewer so the only way to see the file is to download it.
After a bit of investigation i found that at least for local files you can override this by defining your preferred mime types in ~/.local/share/mime/globs2 as follows:
The first field is the priority (smaller number means more important), then follows the mime type, then the pattern that you are matching. The default rules (/usr/local/share/ ...) have a priority of 50 for .c, .h and so on.
For remotely-served files, the browser relies on the MIME Type supplied by the server and the trick above does not work.
Looking at the Chromium sources
it seems that a partial fix can be achieved by arring the list of types we want to display to the array
Maybe we can have some optional patch to the FreeBSD port, although i'd rather find a way to override the server-supplied mime type in a way that does not require rebuilding Chrome.
Anyways, at least for local browsing, this seems a significant improvement.
This method is kind of long and tedious and it still involves downloading the source files, but I can't come up with better right now.
If you click on a link it will automatically download, then if you open the downloads tab (clicking on show all downloads or Ctrl + J) and click Copy link address in the right click menu of the file you downloaded and paste that link in the address bar it will display the file as plain text, but this only works for local files afaik.
Or you can set your file associations for c files to chrome and when you click on a downloaded file it will open up in the browser itself.
How are you getting the URL of the
If it's via a link on another page the Chrome should just open them as plain text files. Well it did for me when I just tried it with a file from my hard drive.
If you want to use Chrome as the default viewer for