I'm writing a program and I need to implement opening a particular file in a text editor. The file type has a different association by default (it's associated to the program itself), so calling
xdg-open $file wouldn't work. Using
$EDITOR is sub-optimal because it usually contains the terminal text editor, and I'd like to open a GUI text editor if that's the first preference. It is also unclear how to find the default terminal emulator to open a terminal
I can query the (possibly GUI) editor with
xdg-mime query default text/plain, which gives me a
.desktop file, but I'm not sure how to go about actually running it, especially since it may contain
Terminal=true which then again raises an issue of figuring out what the default terminal is.
To clarify, the program is not a script or something which already runs in the terminal. It is a GUI application, so launching a terminal editor would require figuring out what the default terminal is.
So, what's the best way to programmatically open a file in a default, possibly GUI, text editor?