Merge branch 'hykilpikonna:master' into master

This commit is contained in:
Harvey 2024-05-13 10:41:09 -05:00 committed by GitHub
commit 22c8d76193
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 691 additions and 110 deletions

View file

@ -1 +1 @@
VERSION = '1.4.11'
VERSION = '1.5.0alpha1'

View file

@ -31,6 +31,7 @@ IS_WINDOWS = platform.system() == 'Windows'
CACHE_PATH = Path(os.getenv("LOCALAPPDATA") or os.getenv("XDG_CACHE_HOME") or Path.home() / '.cache') / 'hyfetch'
@dataclass
class GlobalConfig:
# Global color mode default to 8-bit for compatibility
@ -49,6 +50,4 @@ class GlobalConfig:
return 0.65 if term.lower() == 'dark' else 0.4
GLOBAL_CFG = GlobalConfig(color_mode='8bit', override_distro=None, debug=False, is_light=False, use_overlay=False)
GIT_URL = 'https://github.com/git-for-windows/git/releases/download/v2.37.2.windows.2/Git-2.37.2.2-32-bit.tar.bz2'
GLOBAL_CFG = GlobalConfig(color_mode='8bit', override_distro=None, debug=False, is_light=False, use_overlay=True)

View file

@ -7,23 +7,21 @@ import shlex
import shutil
import subprocess
import sys
import tarfile
from dataclasses import dataclass
from pathlib import Path
from subprocess import check_output
from tempfile import TemporaryDirectory
from typing import Iterable
import pkg_resources
from .color_util import color, printc
from .constants import GLOBAL_CFG, GIT_URL, IS_WINDOWS
from .constants import GLOBAL_CFG, IS_WINDOWS
from .distros import distro_detector
from .presets import ColorProfile
from .serializer import from_dict
from .types import BackendLiteral, ColorAlignMode
RE_NEOFETCH_COLOR = re.compile('\\${c[0-9]}')
SRC = Path(__file__).parent
def literal_input(prompt: str, options: Iterable[str], default: str, show_ops: bool = True) -> str:
@ -197,24 +195,13 @@ def get_command_path() -> str:
:return: Command path
"""
cmd_path = pkg_resources.resource_filename(__name__, 'scripts/neowofetch')
cmd_path = (if_file(SRC.parent / 'neofetch') or if_file(SRC / 'scripts/neowofetch'))
# Windows doesn't support symbolic links, but also I can't detect symbolic links... hard-code it here for now.
if IS_WINDOWS:
pkg = Path(__file__).parent
pth = (shutil.which("neowofetch") or
if_file(cmd_path) or
if_file(pkg / 'scripts/neowofetch') or
if_file(pkg.parent / 'neofetch') or
if_file(Path(cmd_path).parent.parent.parent / 'neofetch'))
if not cmd_path:
printc("&cError: Neofetch script cannot be found")
exit(127)
if not pth:
printc("&cError: Neofetch script cannot be found")
exit(127)
return str(pth)
return cmd_path
return str(cmd_path)
def ensure_git_bash() -> Path:
@ -223,48 +210,19 @@ def ensure_git_bash() -> Path:
:returns git bash path
"""
if IS_WINDOWS:
# Find installation in default path
def_path = Path(r'C:\Program Files\Git\bin\bash.exe')
if def_path.is_file():
return def_path
if not IS_WINDOWS:
return Path('/usr/bin/bash')
# Detect third-party git.exe in path
git_exe = shutil.which("bash") or shutil.which("git.exe") or shutil.which("git")
if git_exe is not None:
pth = Path(git_exe).parent
if (pth / r'bash.exe').is_file():
return pth / r'bash.exe'
elif (pth / r'bin\bash.exe').is_file():
return pth / r'bin\bash.exe'
# Bundled git bash
git_path = (if_file(SRC / 'git/bin/bash.exe')
or if_file("C:/Program Files/Git/bin/bash.exe")
or if_file("C:/Program Files (x86)/Git/bin/bash.exe"))
# Find installation in PATH (C:\Program Files\Git\cmd should be in path)
pth = (os.environ.get('PATH') or '').lower().split(';')
pth = [p for p in pth if p.endswith(r'\git\cmd')]
if pth:
return Path(pth[0]).parent / r'bin\bash.exe'
if not git_path.is_file():
printc("&cError: Git Bash installation not found")
sys.exit(127)
# Previously downloaded portable installation
path = Path(__file__).parent / 'min_git'
portable_bash_exe = path / r'bin\bash.exe'
if path.is_dir() and portable_bash_exe.is_file():
return portable_bash_exe
# No installation found, download a portable installation
Path.mkdir(path, parents=True, exist_ok=True)
pkg_path = path / 'package.tbz'
print('Git installation not found. Git Bash is required to use HyFetch/neofetch on Windows')
if literal_input('Would you like to download and install Git into HyFetch package directory? (if no is selected colors almost certainly won\'t work)', ['yes', 'no'], 'yes', False) == 'yes':
print('Downloading a portable version of Git...')
from urllib.request import urlretrieve
urlretrieve(GIT_URL, pkg_path)
print('Download finished! Extracting...')
with tarfile.open(pkg_path, 'r:bz2') as tbz_ref:
tbz_ref.extractall(path)
print('Done!')
return portable_bash_exe
else:
sys.exit()
return git_path
def check_windows_cmd():
@ -272,14 +230,14 @@ def check_windows_cmd():
Check if this script is running under cmd.exe. If so, launch an external window with git bash
since cmd doesn't support RGB colors.
"""
if IS_WINDOWS:
import psutil
# TODO: This line does not correctly identify cmd prompts...
if psutil.Process(os.getppid()).name().lower().strip() == 'cmd.exe':
print("cmd.exe doesn't support RGB colors, restarting in MinTTY...")
cmd = f'"{ensure_git_bash().parent.parent / "usr/bin/mintty.exe"}" -s 110,40 -e python -m hyfetch --ask-exit'
os.system(cmd)
sys.exit(0)
# if IS_WINDOWS:
# import psutil
# # TODO: This line does not correctly identify cmd prompts...
# if psutil.Process(os.getppid()).name().lower().strip() == 'cmd.exe':
# print("cmd.exe doesn't support RGB colors, restarting in MinTTY...")
# cmd = f'"{ensure_git_bash().parent.parent / "usr/bin/mintty.exe"}" -s 110,40 -e python -m hyfetch --ask-exit'
# os.system(cmd)
# sys.exit(0)
def run_neofetch_cmd(args: str, pipe: bool = False) -> str | None:
@ -293,8 +251,7 @@ def run_neofetch_cmd(args: str, pipe: bool = False) -> str | None:
cmd = get_command_path().replace("\\", "/").replace("C:/", "/c/")
args = args.replace('\\', '/').replace('C:/', '/c/')
full_cmd = [ensure_git_bash(), '-c', f"'{cmd}' {args}"]
# print(full_cmd)
full_cmd = [ensure_git_bash(), cmd, *shlex.split(args)]
if pipe:
return check_output(full_cmd).decode().strip()
@ -353,10 +310,10 @@ def run(asc: str, backend: BackendLiteral, args: str = ''):
def run_qwqfetch(asc: str, args: str = ''):
"""
Run neofetch with colors
Run qwqfetch with colors
:param preset: Color palette
:param alignment: Color alignment settings
:param asc: Ascii art
:param args: Additional arguments to pass to qwqfetch
"""
asc = asc.replace('\\', '\\\\')
@ -369,7 +326,8 @@ def run_qwqfetch(asc: str, args: str = ''):
except ImportError as e: # module not found etc
print("qwqfetch is not installed. Install it by executing:") # use print to output hint directly
print("pip install git+https://github.com/nexplorer-3e/qwqfetch") # TODO: public repo
raise e
exit(127)
def run_neofetch(asc: str, args: str = ''):
"""
@ -401,6 +359,16 @@ def run_fastfetch(asc: str, args: str = '', legacy: bool = False):
:param args: Additional arguments to pass to fastfetch
:param legacy: Set true when using fastfetch < 1.8.0
"""
# Find fastfetch binary
ff_path = (shutil.which('fastfetch')
or if_file(SRC / 'fastfetch/usr/bin/fastfetch')
or if_file(SRC / 'fastfetch/fastfetch')
or if_file(SRC / 'fastfetch/fastfetch.exe'))
if not ff_path:
printc("&cError: fastfetch binary is not found. Please install fastfetch first.")
exit(127)
# Write temp file
with TemporaryDirectory() as tmp_dir:
tmp_dir = Path(tmp_dir)
@ -408,7 +376,7 @@ def run_fastfetch(asc: str, args: str = '', legacy: bool = False):
path.write_text(asc)
# Call fastfetch with the temp file
proc = subprocess.run(['fastfetch', '--raw' if legacy else '--file-raw', path.absolute(), *shlex.split(args)])
proc = subprocess.run([ff_path, '--raw' if legacy else '--file-raw', path.absolute(), *shlex.split(args)])
if proc.returncode == 144:
printc("&6Error code 144 detected: Please upgrade fastfetch to >=1.8.0 or use the 'fastfetch-old' backend")

View file

@ -519,6 +519,27 @@ PRESETS: dict[str, ColorProfile] = {
'#5276D4',
]).with_weights([1, 1, 1, 1, 1, 5, 5, 5])),
# sourced from https://commons.wikimedia.org/wiki/File:Girlflux_Pride_Flag.jpg
"girlflux": ColorProfile([
"f9e6d7",
"f2526c",
"bf0311",
"e9c587",
"bf0311",
"f2526c",
"f9e6d7",
]),
# sourced from https://www.deviantart.com/pride-flags/art/Genderflux-1-543925589
"genderflux": ColorProfile([
"f47694",
"f2a2b9",
"cecece",
"7ce0f7",
"3ecdf9",
"fff48d",
]),
"finsexual": ColorProfile([
"#B18EDF",
"#D7B1E2",
@ -649,6 +670,14 @@ PRESETS: dict[str, ColorProfile] = {
"#89C7B0",
"#F3EDBD",
]),
# sampled from https://es.m.wikipedia.org/wiki/Archivo:Fraysexual_flag.jpg
'fraysexual': ColorProfile([
'#226CB5',
'#94E7DD',
'#FFFFFF',
'#636363',
]),
# Meme flags
'beiyang': ColorProfile([