From 3dbba90ba7644aa7a47bd511823bf66a4f57b22c Mon Sep 17 00:00:00 2001 From: Mark Landis <25310987+anonymouspage@users.noreply.github.com> Date: Sat, 21 Mar 2026 01:50:47 -0700 Subject: [PATCH] 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 --- cmake.packaging/CMakeLists.txt | 5 +++++ cmake.packaging/postinst | 9 +++++++++ cmake.packaging/prerm | 10 ++++++++++ 3 files changed, 24 insertions(+) create mode 100755 cmake.packaging/postinst create mode 100755 cmake.packaging/prerm diff --git a/cmake.packaging/CMakeLists.txt b/cmake.packaging/CMakeLists.txt index 940f213acb..584db2b85e 100644 --- a/cmake.packaging/CMakeLists.txt +++ b/cmake.packaging/CMakeLists.txt @@ -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() diff --git a/cmake.packaging/postinst b/cmake.packaging/postinst new file mode 100755 index 0000000000..9debcd7cff --- /dev/null +++ b/cmake.packaging/postinst @@ -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 diff --git a/cmake.packaging/prerm b/cmake.packaging/prerm new file mode 100755 index 0000000000..345e0270dd --- /dev/null +++ b/cmake.packaging/prerm @@ -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