Skip to content

No fallback on windows ... always fails on windows if no editor is open #96

@BananaAcid

Description

@BananaAcid

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions