Sublime syntax highlighting for systemd unit files
Sublime Text is my go-to editor for system administration duties (since I automate configuration management, I don’t edit config files over SSH with vim too often.)
I was surprised to see just how much I missed syntax highlighting when I was managing systemd unit files. It turns out writing a sublime-syntax file isn’t too hard.
Feel free to drop this in your Sublime packages folder as Systemd.sublime-syntax and you should get some basic formatting help!
- match: '^([A-Za-z]+(?=([\=][\-]?)))'
- match: '^\[[A-Za-z]+\]'
- match: '(\\\w)?'
- match: '\\'
- match: '\#\w+'
Here’s what the matches are hitting against (in order of appearance):
- Directives (ex “ExecStartPre=”)
- Unit sections (ex “[Service]”)
- Multiple line command escape (ex “\” where newlines are inserted for formatting reasons)
- Comments (starting with a “#”)
A couple sites helped me get to the point where I could write this. First, the Sublime Text Unofficial Documentation project. Also, because it’s based on Macromates, their documentation on language grammars.
As far as I can tell, this is the only systemd unit file syntax highlighting file out there, so please leave a comment if you have improvements. If others find this useful, I’ll package it so you can install with Package Control.