Article by editor Leo thinkabit.ukim@gmail.com
The Linux distro I contribute to, Alpine Linux, uses build recipes called
APKBUILDs. They are shell scripts but with context-aware variables that can
affect the final result of package. APKBUILDs are subject to policies that only
apply to Alpine Linux and its packaging system abuild.
Vim is a text editor used by many of our developers and users use for editing APKBUILDs. But while vim has a filetype for shellscripts, it is insufficient to provide syntax, plugins, indentation and other nice to have features that are specific to the context of an APKBUILD.
In light of that I took upon myself to write a complete implementation of
a vim filetype for APKBUILDs.
Meet APKBUILD.vim.
The Whole Deal
APKBUILD.vim is a plugin for Vim and Neovim, that provides:
- Syntax Highlighting:
1.1. Different colors for variables that affectabuildbehavior.
1.2.Errorhighlighting for invalid values insideabuildvariables, like non-existent arches inarch. 1.4. Highlighting ofsecfixes:blocks, version identifiers and recognized security identifiers (CVE, XSA, etc).
1.5. It is built on top ofsh.vim. That means all the syntax highlighting offiletype=shis still in place. - Configuration:
2.1. Sets correcttextwidthof 80 columns.
2.2: Setsnoexpandtabas APKBUILD use tabs for indentation.
2.3: Setssofttabstopto 0.
2.4: Setstabstopandshiftwidthto 4 - ALE Integration:
3.1. Provides a script to run shellcheck with APKBUILD aware filtering and register it into ALE.
3.2. Adds support for the lintersapkbuild-lintandsecfixes-checkfrom atools and registers a handler for them.
Pictures
Here are some comparisons of APKBUILDs with filetype=sh and filetype=APKBUILD:
Main block of variables used by
abuild, notice that the variables that are fromabuildhave a different color than the ones normally used by shell.


Comparison of secfixes, notice how the
secfixes:declaration, the versions and the security identifiers are all highlighted.


General comparison of
Errorhighlighting.

