diff options
author | Anton Kriese <anton.kriese@gmx.de> | 2022-11-24 13:13:36 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2023-01-16 11:26:57 +0100 |
commit | 52268afb1cc47ca5ac91ca265e95827bff2901bd (patch) | |
tree | fe8c67feecba311124051c125abc903608931030 /src/nvim/os/fs.c | |
parent | 34b973b1d9e3b0c6f546e3aa661c29edd5a1ab87 (diff) | |
download | rneovim-52268afb1cc47ca5ac91ca265e95827bff2901bd.tar.gz rneovim-52268afb1cc47ca5ac91ca265e95827bff2901bd.tar.bz2 rneovim-52268afb1cc47ca5ac91ca265e95827bff2901bd.zip |
fix(exepath)!: prefers extensionless for powershell
PROBLEM:
exepath("test") should prefer ".bat" when shell=powershell.
Current behavior differs from Vim 8.2.3071.
TEST CASE:
1. in a folder which is in $PATH, create files "test" "test.bat".
- "(Get-Command test).Path test" returns "test.bat".
2. compare nvim:
nvim --clean
:set shell=powershell
:echo exepath("test")
3. should returns "path\to\test.bat" (before this patch it returns "path\to\test").
SOLUTION:
After this patch, the binary files "text.exe", "test.bat", "test.com"
will be found, but the file "test" (without any extension) will not be
found (matches Vim 8.2.3071). But powershell's `where` and
`Get-Command` _do_ find the extensionless 'test' file.
But Nvim with ":set shell=cmd.exe", doesn't find "test" either (before
and after this patch), even though `where test` returns correct path in
cmd.
- `where` is a program to find files in general, not just executable files.
-`Get-Command` returning extensionless (and thus non-executable) file is
puzzling even to Chris Dent, [PowerShell expert][1] (asked on
Discord).
[1]: https://www.amazon.com/Mastering-PowerShell-Scripting-Automate-environment-ebook/dp/B0971MG88X
Co-authored-by: Enan Ajmain <3nan.ajmain@gmail.com>
Helped-by: erw7 <erw7.github@gmail.com>
Fixes #21045
Diffstat (limited to 'src/nvim/os/fs.c')
-rw-r--r-- | src/nvim/os/fs.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index e0449d468a..98ec9aa826 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -302,7 +302,9 @@ static bool is_executable(const char *name, char **abspath) static bool is_executable_ext(const char *name, char **abspath) FUNC_ATTR_NONNULL_ARG(1) { - const bool is_unix_shell = strstr((char *)path_tail(p_sh), "sh") != NULL; + const bool is_unix_shell = strstr(path_tail(p_sh), "powershell") == NULL + && strstr(path_tail(p_sh), "pwsh") == NULL + && strstr(path_tail(p_sh), "sh") != NULL; char *nameext = strrchr(name, '.'); size_t nameext_len = nameext ? strlen(nameext) : 0; xstrlcpy(os_buf, name, sizeof(os_buf)); |