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
0 commit comments