I'm trying to record how a file changes over time down to the smallest details, which means that reading any changes per file save wouldn't give sufficient data for my use-case, it needs to be per-keystroke.
I just tried out inotify, but it can only notify me on file-save, not file-modification.
I then realized (I'm quite inexperienced with file-system stuff) that this is because text-editors use buffers to store yet-to-happen changes, committing the contents of the buffer on file save (I think, at least).
So, it seems to me that I could
- read the buffer of a text-editor (which seems like it would have to be code specific to each particular editor; not viable)
- force a save to the file on every keypress (which again seems like it would require editor-specific code)
- monitor the keypresses of the user, store my own buffer of them, and then once the file is saved, correlate the keypresses with the diff (this seems way too hard and prone to error)
- read the contents of the file on an interval faster than a person is likely the press any keys (this is hacky, and ridiculous)
I can't think of any other ways. It seems that to properly get the behavior I want I'd need to have editing occur within the terminal, or within a web form. I'd love to hear other ideas though, or a potential editor-agnostic solution to this problem. Thank you for your time.