Fix escaping issue for shell commands
I am using overseer.nvim in conjunction with cmake-tools.nvim.
In cmake-tools I defined a task as
{
cmake_command = "source /home/ubuntu/setup.sh && cmake", -- I am doing cross compilation and need specific $PATH and such
cmake_generate_options = { "-DCMAKE_EXPORT_COMPILE_COMMANDS=1", "-GNinja", " -DCMAKE_C_COMPILER_LAUNCHER=ccache", "-DCMAKE_CXX_COMPILER_LAUNCHER=ccache" }
}
from which cmake-tasks constructs an overseer task, so far so good. However, the following command gets escaped by overseer, and ends up being sent to the shell (bash) as
'source /home/ubuntu/setup.sh && cmake' -B /home/arnaud/devel/fotowall/build/Debug -S . -D CMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -GNinja
which obviously does not work: the command is escaped out between single quotes '...'.
FAILURE: 'source /home/ubuntu/setup.sh && cmake' -B /home/arnaud/devel/fotowall/build/Debug -S . -D CMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -GNinja
out: zsh:1: no such file or directory: source /home/ubuntu/setup.sh && cmake
A simple way to simulate this failure is to run bash -c "'echo test1' && echo test2" in a terminal, which gives bash: line 1: echo test1: command not found
The patch in this PR removes escaping of the command, and leaves it for the arguments. This works in this case, but I am unsure if it might break other use cases.
This is a tricky edge case that is not well documented, so apologies for that. As you have discovered, when you pass in a string for the command it is run in the shell, but that still gets escaped. However, what you may not have noticed is that the escaping only happens if you also pass in args.
https://github.com/stevearc/overseer.nvim/blob/fae72477853a9cac141b2c95a726ebc00ef4a88a/lua/overseer/task.lua#L83-L92
Is it possible for you to pass all of those arguments in with the command string? If so, that should solve your issue.