How to get Mac OSX Finder to preview programming text files that don’t have .txt or .text extension?

MacOS

Question or issue on macOS:

Programming obviously involves lots of text file usage. You often want to see what you did somewhere else in some other program, without loading up that whole program into your current IDE of choice.

If I copy a text file from say fred.cpp to fred.cpp.text, I can view the contents of the file from the Finder’s preview. But I don’t want to have copy or rename all my development files.

In a 2003 (!) post on MacOSHints, there is an instruction to do this

find . -name *.xml -exec SetFile -t TEXT {} ;

(in that case, for *.xml files), but this didn’t work for me due to issues with the exec command. But in any case, surely there’s a better way to do it from the GUI?

Either way though: a command-line or a GUI solution would be great, thanks!

How to solve this problem?

Solution no. 1:

There is the Textmate QuickLook plugin which only works with Textmate running.

Pro: Syntax Highlighting
Contra: Only with (non-free) Textmate running


Alternatively: QLStephen


QLStephen is an Apple OSX QuickLook plugin that lets you view plain text files without a file extension.

But it works for all plain text files (even with extension).

Pro: Stable and free
Contra: No syntax highlighting

Solution no. 2:

2 years late but you can use

https://github.com/anthonygelibert/QLColorCode

install via brew cask
brew cask install qlcolorcode

for more nice usages of the quicklook, check this repo

https://github.com/sindresorhus/quick-look-plugins

Hope this helps!