From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: demostanis Date: Sat, 10 Sep 2022 23:32:51 +0200 Subject: [PATCH] Use bash instead of /bin/sh --- src/shell_manager.cc | 43 +++++-------------------------------------- 1 file changed, 5 insertions(+), 38 deletions(-) diff --git a/src/shell_manager.cc b/src/shell_manager.cc index 96cfb06..4eb71db 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -34,44 +34,11 @@ namespace Kakoune ShellManager::ShellManager(ConstArrayView builtin_env_vars) : m_env_vars{builtin_env_vars} { - auto is_executable = [](StringView path) { - struct stat st; - if (stat(path.zstr(), &st)) - return false; - - bool executable = (st.st_mode & S_IXUSR) - | (st.st_mode & S_IXGRP) - | (st.st_mode & S_IXOTH); - return S_ISREG(st.st_mode) and executable; - }; - - if (const char* shell = getenv("KAKOUNE_POSIX_SHELL")) - { - if (not is_executable(shell)) - throw runtime_error{format("KAKOUNE_POSIX_SHELL '{}' is not executable", shell)}; - m_shell = shell; - } - else // Get a guaranteed to be POSIX shell binary - { - #if defined(_CS_PATH) - auto size = confstr(_CS_PATH, nullptr, 0); - String path; path.resize(size-1, 0); - confstr(_CS_PATH, path.data(), size); - #else - StringView path = "/bin:/usr/bin"; - #endif - for (auto dir : StringView{path} | split(':')) - { - auto candidate = format("{}/sh", dir); - if (is_executable(candidate)) - { - m_shell = std::move(candidate); - break; - } - } - if (m_shell.empty()) - throw runtime_error{format("unable to find a posix shell in {}", path)}; - } + // We hardcode bash since /bin/sh (/bin/Shell) is not + // a POSIX-compliant shell, that will error out when + // fed with Kakoune's scripts. It is expected to be + // installed along with the port. + m_shell = "/usr/local/bin/bash"; // Add Kakoune binary location to the path to guarantee that %sh{ ... } // have access to the kak command regardless of if the user installed it -- 2.37.3