C++ (Unix): Open a text file with the default editor
c, default, linux, text-editor, unix
Solution
There is no official solution. Here is my recommendation for opening up a text editor:
If the filename extension is `.txt`, and `xdg-open` is avaliable on `$PATH` and the `$DISPLAY` variable is nonempty, then use `xdg-open`. Otherwise use `/usr/bin/sensible-editor` if it exists. Otherwise, use `getenv("EDITOR")`, `getenv("VISUAL")` or `getenv("SELECTED_EDITOR")`. If none of them are set, try `nano`, `nano-tiny` and then `vi`.
Problem
The question is above and my Google search wasn't succesfull. I guess I need to get the default editor and then use `system("editor file.txt");`? How could I get the default editor? Edit: I don't know why but stackoverflow doesn't like my "Hey,"... then not.