diff --git a/src/detection/editor/editor.c b/src/detection/editor/editor.c index 6fd5258c5..9ae00eea8 100644 --- a/src/detection/editor/editor.c +++ b/src/detection/editor/editor.c @@ -1,5 +1,6 @@ #include "editor.h" #include "common/processing.h" +#include "common/library.h" #include "util/stringUtils.h" #include "util/path.h" #include "util/binary.h" @@ -13,7 +14,7 @@ static inline char* realpath(const char* restrict file_name, char* restrict reso } #endif -static bool extractNvimVersion(const char* str, uint32_t len, void* userdata) +static bool extractNvimVersionFromBinary(const char* str, uint32_t len, void* userdata) { if (len < strlen("NVIM v0.0.0")) return true; if (!ffStrStartsWith(str, "NVIM v")) return true; @@ -21,7 +22,7 @@ static bool extractNvimVersion(const char* str, uint32_t len, void* userdata) return false; } -static bool extractVimVersion(const char* str, uint32_t len, void* userdata) +static bool extractVimVersionFromBinary(const char* str, uint32_t len, void* userdata) { if (len < strlen("VIM - Vi IMproved 0.0")) return true; if (!ffStrStartsWith(str, "VIM - Vi IMproved ")) return true; @@ -30,7 +31,7 @@ static bool extractVimVersion(const char* str, uint32_t len, void* userdata) return false; } -static bool extractNanoVersion(const char* str, uint32_t len, void* userdata) +static bool extractNanoVersionFromBinary(const char* str, uint32_t len, void* userdata) { if (len < strlen("GNU nano 0.0")) return true; if (!ffStrStartsWith(str, "GNU nano ")) return true; @@ -60,13 +61,18 @@ const char* ffDetectEditor(FFEditorResult* result) if (error) return NULL; } - char buf[PATH_MAX + 1]; - if (!realpath(result->path.chars, buf)) - return NULL; + { + char buf[PATH_MAX + 1]; + if (!realpath(result->path.chars, buf)) + return NULL; - // WIN32: Should we handle scoop shim exe here? + // WIN32: Should we handle scoop shim exe here? - ffStrbufSetS(&result->path, buf); + #ifdef __linux__ + if (!ffStrEndsWith(buf, "/snap")) + #endif + ffStrbufSetS(&result->path, buf); + } { uint32_t index = ffStrbufLastIndexC(&result->path, @@ -91,11 +97,11 @@ const char* ffDetectEditor(FFEditorResult* result) if (!instance.config.general.detectVersion) return NULL; if (ffStrbufEqualS(&result->exe, "nvim")) - ffBinaryExtractStrings(buf, extractNvimVersion, &result->version); + ffBinaryExtractStrings(result->path.chars, extractNvimVersionFromBinary, &result->version); else if (ffStrbufEqualS(&result->exe, "vim")) - ffBinaryExtractStrings(buf, extractVimVersion, &result->version); + ffBinaryExtractStrings(result->path.chars, extractVimVersionFromBinary, &result->version); else if (ffStrbufEqualS(&result->exe, "nano")) - ffBinaryExtractStrings(buf, extractNanoVersion, &result->version); + ffBinaryExtractStrings(result->path.chars, extractNanoVersionFromBinary, &result->version); if (result->version.length > 0) return NULL; diff --git a/src/util/path.c b/src/util/path.c index e47cbe768..5a0b5964e 100644 --- a/src/util/path.c +++ b/src/util/path.c @@ -13,14 +13,17 @@ const char* ffFindExecutableInPath(const char* name, FFstrbuf* result) const bool appendExe = !ffStrEndsWithIgnCase(name, ".exe"); #endif - for (char* token = NULL; (token = strchr(path, - #ifdef _WIN32 - ';' - #else - ':' - #endif - )) != NULL; path = token + 1) + for (char* token = path; *token; path = token + 1) { + token = strchr(path, + #ifdef _WIN32 + ';' + #else + ':' + #endif + ); + if (!token) token = path + strlen(path); + ffStrbufSetNS(result, (uint32_t)(token - path), path); ffStrbufEnsureEndsWithC(result, #ifdef _WIN32