From a90ca3c849f78f5dd6c5e88cefd05bc709882b34 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sun, 13 Nov 2022 22:47:23 -0500 Subject: [PATCH] use classic macos file type to identify scripts. --- command.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/command.cpp b/command.cpp index a89a120..d95d6c2 100644 --- a/command.cpp +++ b/command.cpp @@ -26,6 +26,12 @@ #include #include + + +#if defined(__APPLE__) +#include +#endif + extern std::atomic control_c; namespace fs = filesystem; @@ -107,8 +113,22 @@ namespace { } + bool is_script(const fs::path &path) { - return path.extension() == ".text"; + + #if defined(__APPLE__) + /* check for a file type of TEXT */ + + uint8_t finfo[32]; + int ok = getxattr(path.c_str(), XATTR_FINDERINFO_NAME,finfo, sizeof(finfo), 0, 0); + if (ok < 4) return false; + + if (memcmp(finfo, "TEXT", 4) == 0) return true; + return false; + + #else + return path.extension() == ".script"; + #endif } }