From 089f669e6ac0e09a93f9a8026136d5fa289d5014 Mon Sep 17 00:00:00 2001 From: Azalea Gui Date: Tue, 7 Feb 2023 18:41:19 -0500 Subject: [PATCH] [F] Add more detection path for get_command_path #84 --- hyfetch/neofetch_util.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/hyfetch/neofetch_util.py b/hyfetch/neofetch_util.py index cbaceb3e..04ab6a58 100644 --- a/hyfetch/neofetch_util.py +++ b/hyfetch/neofetch_util.py @@ -137,6 +137,16 @@ class ColorAlignment: return asc +def if_file(f: str | Path) -> Path | None: + """ + Return the file if the file exists, or return none. Useful for chaining 'or's + """ + f = Path(f) + if f.is_file(): + return f + return None + + def get_command_path() -> str: """ Get the absolute path of the neofetch command @@ -147,7 +157,15 @@ def get_command_path() -> str: # Windows doesn't support symbolic links, but also I can't detect symbolic links... hard-code it here for now. if platform.system() == 'Windows': - return str(Path(cmd_path).parent.parent.parent / 'neofetch') + pth = (shutil.which("neowofetch") or + if_file(cmd_path) or + if_file(Path(cmd_path).parent.parent.parent / 'neofetch')) + + if not pth: + printc("&cError: Neofetch script cannot be found") + exit(127) + + return str(pth) return cmd_path