Skip to content

Commit e199a2f

Browse files
committed
Editor: fix bug of executable searching
1 parent b4aac9d commit e199a2f

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

src/detection/editor/editor.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "editor.h"
22
#include "common/processing.h"
3+
#include "common/library.h"
34
#include "util/stringUtils.h"
45
#include "util/path.h"
56
#include "util/binary.h"
@@ -13,15 +14,15 @@ static inline char* realpath(const char* restrict file_name, char* restrict reso
1314
}
1415
#endif
1516

16-
static bool extractNvimVersion(const char* str, uint32_t len, void* userdata)
17+
static bool extractNvimVersionFromBinary(const char* str, uint32_t len, void* userdata)
1718
{
1819
if (len < strlen("NVIM v0.0.0")) return true;
1920
if (!ffStrStartsWith(str, "NVIM v")) return true;
2021
ffStrbufSetS((FFstrbuf*) userdata, str + strlen("NVIM v"));
2122
return false;
2223
}
2324

24-
static bool extractVimVersion(const char* str, uint32_t len, void* userdata)
25+
static bool extractVimVersionFromBinary(const char* str, uint32_t len, void* userdata)
2526
{
2627
if (len < strlen("VIM - Vi IMproved 0.0")) return true;
2728
if (!ffStrStartsWith(str, "VIM - Vi IMproved ")) return true;
@@ -30,7 +31,7 @@ static bool extractVimVersion(const char* str, uint32_t len, void* userdata)
3031
return false;
3132
}
3233

33-
static bool extractNanoVersion(const char* str, uint32_t len, void* userdata)
34+
static bool extractNanoVersionFromBinary(const char* str, uint32_t len, void* userdata)
3435
{
3536
if (len < strlen("GNU nano 0.0")) return true;
3637
if (!ffStrStartsWith(str, "GNU nano ")) return true;
@@ -60,13 +61,18 @@ const char* ffDetectEditor(FFEditorResult* result)
6061
if (error) return NULL;
6162
}
6263

63-
char buf[PATH_MAX + 1];
64-
if (!realpath(result->path.chars, buf))
65-
return NULL;
64+
{
65+
char buf[PATH_MAX + 1];
66+
if (!realpath(result->path.chars, buf))
67+
return NULL;
6668

67-
// WIN32: Should we handle scoop shim exe here?
69+
// WIN32: Should we handle scoop shim exe here?
6870

69-
ffStrbufSetS(&result->path, buf);
71+
#ifdef __linux__
72+
if (!ffStrEndsWith(buf, "/snap"))
73+
#endif
74+
ffStrbufSetS(&result->path, buf);
75+
}
7076

7177
{
7278
uint32_t index = ffStrbufLastIndexC(&result->path,
@@ -91,11 +97,11 @@ const char* ffDetectEditor(FFEditorResult* result)
9197
if (!instance.config.general.detectVersion) return NULL;
9298

9399
if (ffStrbufEqualS(&result->exe, "nvim"))
94-
ffBinaryExtractStrings(buf, extractNvimVersion, &result->version);
100+
ffBinaryExtractStrings(result->path.chars, extractNvimVersionFromBinary, &result->version);
95101
else if (ffStrbufEqualS(&result->exe, "vim"))
96-
ffBinaryExtractStrings(buf, extractVimVersion, &result->version);
102+
ffBinaryExtractStrings(result->path.chars, extractVimVersionFromBinary, &result->version);
97103
else if (ffStrbufEqualS(&result->exe, "nano"))
98-
ffBinaryExtractStrings(buf, extractNanoVersion, &result->version);
104+
ffBinaryExtractStrings(result->path.chars, extractNanoVersionFromBinary, &result->version);
99105

100106
if (result->version.length > 0) return NULL;
101107

src/util/path.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ const char* ffFindExecutableInPath(const char* name, FFstrbuf* result)
1313
const bool appendExe = !ffStrEndsWithIgnCase(name, ".exe");
1414
#endif
1515

16-
for (char* token = NULL; (token = strchr(path,
17-
#ifdef _WIN32
18-
';'
19-
#else
20-
':'
21-
#endif
22-
)) != NULL; path = token + 1)
16+
for (char* token = path; *token; path = token + 1)
2317
{
18+
token = strchr(path,
19+
#ifdef _WIN32
20+
';'
21+
#else
22+
':'
23+
#endif
24+
);
25+
if (!token) token = path + strlen(path);
26+
2427
ffStrbufSetNS(result, (uint32_t)(token - path), path);
2528
ffStrbufEnsureEndsWithC(result,
2629
#ifdef _WIN32

0 commit comments

Comments
 (0)