MacOS uses QuickLook preview to highlight arbitrary code source files
Many source files, such as Flutter.dart files, YAML.yaml,.yml, CocoaPods Podfile, podfile.lock, etc., do not support quick viewing with Spaces by default.
QuickLook doesn’t work even though you can double click on the file to open it through VSCode, Android Studio, etc., by right-clicking the file, showing introduction -> Open mode.
Ordinary.h,.cpp and other source files although the system is recognized, but there is no code highlighting, blind.
Installing a plug-in
Fortunately, there are tons of open source plugins that do this without having to reinvent the wheel.
GitHub Project link: github.com/sindresorhu…
Other information about the QuickLook Plugin:
-
sspai.com/post/31927
-
zhuanlan.zhihu.com/p/57203915
Refer to the two links above for an introduction to QuickLook without further ado.
For the need to highlight preview source files discussed in this article, we can install QLColorCode for code highlighting and QLStephen for previewing files without suffix names.
Installation via Homebrew is recommended for centralized management.
brew cask install qlcolorcode
brew cask install qlstephen
Copy the code
Note that if the macOS version is 10.15 Catalina or later, you need to perform additional operations after installing the plug-in
xattr -r ~/Library/QuickLook
xattr -d -r com.apple.quarantine ~/Library/QuickLook
To resolve the problem of not running the QuickLook plugin
Add extension files
However, even if QLColorCode is installed in the plugin, there is no way to view files such as.dart that are not recognized by the system
Open the ~ / Library/QuickLook/QLColorCode qlgenerator/Contents/Info. The file
Find DocumentTypes > Item 0 > Document ContentType UTIs (CFBundleDocumentTypes > Item 0 > LSItemContentTypes
Click ➕ to add a one-line.dart file format, as shown in the image above
com.apple.disk-image-dart
Copy the code
It takes effect immediately after saving. Other types of files can also be previewed by this method.
But how do you check the type of a particular file format?
By this command
mdls -name kMDItemContentType ./main.dart
Copy the code
I can get the file type that was passed in
kMDItemContentType = "com.apple.disk-image-dart"
Copy the code
The common source files are added into the ~ / Library/QuickLook/QLColorCode qlgenerator/Contents/Info. The plist, production efficiency greatly improve 💪
reference
-
medium.com/@claudmarot…
-
Github.com/anthonygeli…
-
Github.com/whomwah/qls…