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 affectabuild
behavior.
1.2.Error
highlighting for invalid values insideabuild
variables, 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=sh
is still in place. - Configuration:
2.1. Sets correcttextwidth
of 80 columns.
2.2: Setsnoexpandtab
as APKBUILD use tabs for indentation.
2.3: Setssofttabstop
to 0.
2.4: Setstabstop
andshiftwidth
to 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-lint
andsecfixes-check
from 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 fromabuild
have 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
Error
highlighting.