La pregunta está arriba y mi búsqueda en Google no tuvo éxito. Supongo que necesito obtener el editor predeterminado y luego usar system("editor file.txt"); ? ¿Cómo podría obtener el editor predeterminado?
Editar: no sé por qué, pero a stackoverflow no le gusta mi "Oye"... entonces no.
No hay una solución oficial. Aquí está mi recomendación para abrir un editor de texto:
Si la extensión del nombre de archivo es .txt y xdg-open está disponible en $PATH y la variable $DISPLAY no está vacía, utilice xdg-open . De lo contrario, use /usr/bin/sensible-editor si existe. De lo contrario, use getenv("EDITOR") , getenv("VISUAL") o getenv("SELECTED_EDITOR") . Si ninguno de ellos está configurado, pruebe nano , nano-tiny y luego vi .
Hay un ejemplo para obtener el entorno del editor predeterminado, desde visudo (Usa el editor predeterminado para abrir el archivo sudoers) fuente
/* * Check EDITOR and VISUAL environment variables to see which editor * the user wants to use (we may not end up using it though). * If the path is not fully-qualified, make it so and check that * the specified executable actually exists. */ if ((UserEditor = getenv("EDITOR")) == NULL || *UserEditor == '\0') UserEditor = getenv("VISUAL"); if (UserEditor && *UserEditor == '\0') UserEditor = NULL; else if (UserEditor) { if (find_path(UserEditor, &Editor, getenv("PATH")) == FOUND) { UserEditor = Editor; } else { if (def_flag(I_ENV_EDITOR)) { /* If we are honoring $EDITOR this is a fatal error. */ (void) fprintf(stderr, "%s: specified editor (%s) doesn't exist!\n", Argv[0], UserEditor); Exit(-1); } else { /* Otherwise, just ignore $EDITOR. */ UserEditor = NULL; } } }Puede consultar http://www.opensource.apple.com/source/sudo/sudo-9/sudo/visudo.c para obtener el código completo.