Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider using git config editor rather than a separate environment variable named EDITOR #84

Closed
akashRindhe opened this issue Mar 30, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@akashRindhe
Copy link
Contributor

Current Situation

git-plan looks for the user's choice of editor through an environment variable named EDITOR and if such a variable doesn't exist, it defaults to vim.

Enhancement

git users have their choice of editor pre-configured which can be found by running git config --global core.editor. Consider using this configuration.

Reasoning

Reduces the effort for users in having to setup a new environment variable when one already exists in the git domain.

Implementation

Look up the result of git config --global core.editor and default to vim if variable is not set.

@akashRindhe akashRindhe added the enhancement New feature or request label Mar 30, 2021
@Goorzhel
Copy link

EDITOR is a pretty ubiquitous env var, but here's a first pass (since there's only one place an editor is looked for):

diff --git a/git_plan/service/plan.py b/git_plan/service/plan.py
index cb60191..8ba2bfb 100644
--- a/git_plan/service/plan.py
+++ b/git_plan/service/plan.py
@@ -4,9 +4,9 @@
 """
 import os
 import tempfile
 import time
-from subprocess import call
+from subprocess import call, getoutput
 from typing import List

 from git_plan.exceptions import PlanEmpty
 from git_plan.model.commit import Commit, CommitMessage
@@ -87,9 +87,11 @@ class PlanService:
     def _prompt_user_for_plan(self, initial: str = None) -> CommitMessage:
         if not initial:
             initial = self._plan_template

-        editor = os.environ.get('EDITOR', 'vim')
+        editor = getoutput('git config --global core.editor')
+        if not editor:
+            editor = os.environ.get('EDITOR', 'vim')
         if not is_installed(editor):
             raise RuntimeError("Couldn't find an editor installed on your system.")

         with tempfile.NamedTemporaryFile(suffix=".tmp", mode='r+') as file:

@rorybyrne
Copy link
Owner

This sounds reasonable, it makes sense to use existing git configuration wherever possible.

I'm happy to take a PR for this but the subprocess call should be a method in the GitService.

@akashRindhe
Copy link
Contributor Author

Fixed in #85, so closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants