build: update-alternatives during deb install #37980

Problem:
nvim is not added to the system alternatives index when installed via
the .deb package, requiring users to explicitly invoke nvim rather than
use 'vi' or 'vim' alternatives.

Solution:
Invoke update-alternatives in CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
steps.

Co-authored-by: Mark Landis <anonymouspage@limsei.com>
This commit is contained in:
Mark Landis
2026-03-21 01:50:47 -07:00
committed by GitHub
parent 0655a359ae
commit 3dbba90ba7
3 changed files with 24 additions and 0 deletions

View File

@@ -70,6 +70,11 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# Unfortunately, you "just need to know" that this has a hidden
# dependency on dpkg-shlibdeps whilst using a debian based host.
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS TRUE)
# Include postinst and prerm scripts for update-alternatives
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
"${CMAKE_CURRENT_LIST_DIR}/postinst"
"${CMAKE_CURRENT_LIST_DIR}/prerm")
else()
set(CPACK_GENERATOR TGZ)
endif()

9
cmake.packaging/postinst Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/sh
set -e
# Register nvim as an alternative for vi and vim, view, editor
update-alternatives --install /usr/bin/vi vi /usr/bin/nvim 60
update-alternatives --install /usr/bin/vim vim /usr/bin/nvim 60
update-alternatives --install /usr/bin/view view /usr/bin/nvim 60
exit 0

10
cmake.packaging/prerm Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/sh
set -e
if [ "$1" = "remove" ]; then
update-alternatives --remove vi /usr/bin/nvim
update-alternatives --remove vim /usr/bin/nvim
update-alternatives --remove view /usr/bin/nvim
fi
exit 0