Is there an approved way for to query whether a document is open an editor in Linux?
For example, if a document is being edited we may want to warn that a document is open and should be saved before a git
merge or pull. We might also want to avoid automated housekeeping (removing trailing whitespace etc.) on files being actively edited.
There are three obvious but flawed methods.
- Test whether the file is open using
lsof
. However most editors do not leave the file open while editing the document. - Check whether an editor window is open with
wmctrl -l
. This is limited to X editors, and even then only if the document is the active tab. - See if there is a temporary file. For example, if the file
.foo.swp
exists we might presume the filefoo
is open invim
, particularly if.foo.swp
is newer thanfoo
. However, there isn't a uniform naming scheme across editors, and some editors likeLyX
may not create the temporary file instantly.
So is there a recommended way of telling whether a document is open in an editor that works on all editors (or at least editors compliant with some Gnome/KDE/other standard)?