Skip to content

Commit

Permalink
[F] Add more detection path for get_command_path #84
Browse files Browse the repository at this point in the history
  • Loading branch information
hykilpikonna committed Feb 7, 2023
1 parent 212ac1a commit 089f669
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion hyfetch/neofetch_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ def recolor_ascii(self, asc: str, preset: ColorProfile) -> str:
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
Expand All @@ -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

Expand Down

0 comments on commit 089f669

Please sign in to comment.