Since it is uncommon for windows to have EDITOR or VISUAL set, I added:
( There also seems no way to prevent launch-editor from wrapping my error-callback to not log a not format matching error like the rest of my cli app ... )
import launchEditorX from 'launch-editor';
import open from 'open';
function launchEditor(file: string, errCb?:(file:string, errorMessage:string | null) => void): void {
function reject(file:string, errorMessage:string | null) {
// log that the user needs to select an editor himself
console.error(colors.red(figures.warning), 'Please select an editor yourself.');
// just throw the file at the OS and try to let it handle it
// (in this project, these will be text files, so we do not care)
open(file, { wait: false });
}
// set the VISUAL env as default if none is available, looking at you windows
// DO NOT use LAUNCH_EDITOR, since we do not always enforce notepad, just use as fallback.
if (!process.env.VISUAL && !process.env.EDITOR)
process.env.VISUAL =
/^win/.test(process.platform) ? "notepad" : // this is required!
"vim"; // VISUAL | EDITOR should not require this
// try already opened editors, fall back to env VISUAL | EDITOR
launchEditorX(file, errCb ?? reject);
}
Since it is uncommon for windows to have
EDITORorVISUALset, I added:( There also seems no way to prevent launch-editor from wrapping my error-callback to not log a not format matching error like the rest of my cli app ... )