From 192e142869184aa5ee55bf2657be120f824616b8 Mon Sep 17 00:00:00 2001 From: Julien Castelain Date: Sun, 24 Nov 2019 00:45:25 +0100 Subject: [PATCH] fix: check for editor in environment variables To determine which editor to use for commit messages look if $EDITOR or $VISUAL are set in the environment before checking the git config. If no editor is found throw an error. Fixes #745 --- package-lock.json | 2 +- src/utils.ts | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0c839e49..9fc7d693 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "gh", - "version": "2.8.1", + "version": "2.8.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/utils.ts b/src/utils.ts index 11dcf052..6a91e6fc 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -77,7 +77,15 @@ export function openFileInEditor(fileName: string, msg: string): string { writeFileSync(filePath, msg) - const editor = spawnSync('git', ['config', '--global', 'core.editor']).stdout + const editor = process.env.EDITOR + ? process.env.EDITOR + : process.env.VISUAL + ? process.env.VISUAL + : spawnSync('git', ['config', '--global', 'core.editor']).stdout + + if (!editor) { + throw new Error('Could not determine which editor to use') + } execSyncInteractiveStream(`${editor} "${filePath}"`)