From 649ffabfa6cc7683269ec9528096b6e58418b497 Mon Sep 17 00:00:00 2001 From: suly520 Date: Fri, 10 Mar 2023 17:18:22 +0100 Subject: [PATCH] **Bugfix** **Enhanced** on Windows 11 Hello, I made a few changes. **Bugfix**: self.pane.get_file_under_cursor() returns wrong path **Enhanced**: get git path Tested only on Win11 but should work on linux to --- openingithub/__init__.py | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/openingithub/__init__.py b/openingithub/__init__.py index 2b98962..ad9b98a 100644 --- a/openingithub/__init__.py +++ b/openingithub/__init__.py @@ -1,18 +1,23 @@ -from subprocess import Popen -import platform -from fman import DirectoryPaneCommand, show_alert, load_json +import shutil +import subprocess +from fman import DirectoryPaneCommand, show_alert -PLUGIN_SETTINGS = load_json("OpenInGithub Settings.json")[0] -GITHUB_BINARY = PLUGIN_SETTINGS["github_binary"] -class OpenInGithub(DirectoryPaneCommand): - def __call__(self): - file_under_cursor = self.pane.get_file_under_cursor() - if file_under_cursor: - if platform.system() == "Windows": - Popen('"%s" %s' % (GITHUB_BINARY, file_under_cursor), shell=True) - else: - Popen('%s "%s"' % (GITHUB_BINARY, file_under_cursor), shell=True) +GITHUB_PATH = shutil.which("github") + +if GITHUB_PATH is None: + raise ValueError("Github command-line tool not found in PATH. Please install Github or add it to your PATH.") - else: - show_alert("No file selected.") +class OpenInGithub(DirectoryPaneCommand): + def __call__(self): + file_under_cursor_unf = self.pane.get_file_under_cursor() + file_under_cursor = file_under_cursor_unf if not file_under_cursor_unf.startswith("file://") else file_under_cursor_unf[7:] + + if not file_under_cursor: + show_alert("No file selected.") + return + try: + subprocess.run([GITHUB_PATH, file_under_cursor], shell=True) + + except subprocess.CalledProcessError: + show_alert("Failed to open file in Github.")