Created
May 14, 2025 02:29
-
-
Save zenspider/8dfcceadc6f3777d94bcffee8db550d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env -S ruby -w | |
$: << File.expand_path("~/Links/RI/lib") | |
$: << File.expand_path("~/Links/ZT/lib") | |
require "rubygems" | |
require "inline" | |
class X | |
inline :C do |builder| | |
builder.include "<CoreServices/CoreServices.h>" | |
builder.prefix <<~'EOC' | |
static _Noreturn void callback(ConstFSEventStreamRef streamRef, | |
void *clientCallBackInfo, | |
size_t numEvents, | |
void *eventPaths, | |
const FSEventStreamEventFlags eventFlags[], | |
const FSEventStreamEventId eventIds[]) { | |
for (size_t i = 0; i < numEvents; i++) { | |
char* path = ((char**)eventPaths)[i]; | |
printf("%s\n", path); | |
} | |
exit(0); | |
} | |
EOC | |
builder.c <<~EOC | |
void watch(char * path) { | |
CFStringRef pathToWatch = CFStringCreateWithCString(kCFAllocatorDefault, path, kCFStringEncodingUTF8); | |
CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void **)&pathToWatch, 1, NULL); | |
void *callbackInfo = NULL; | |
FSEventStreamRef stream; | |
CFAbsoluteTime latency = 1.0; | |
stream = FSEventStreamCreate(kCFAllocatorDefault, | |
callback, | |
callbackInfo, | |
pathsToWatch, | |
kFSEventStreamEventIdSinceNow, | |
latency, | |
kFSEventStreamCreateFlagNone); | |
// Add stream to run loop | |
FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); | |
FSEventStreamStart(stream); | |
CFRunLoopRun(); | |
// Exit | |
return 2; | |
} | |
EOC | |
end | |
end | |
X.new.watch "/Users/ryan/Work/p4/zss/src" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment