Files
dotfiles/.config/fastfetch/detect_os.py
2026-04-25 10:20:12 +03:00

37 lines
958 B
Python
Executable File

#!/usr/bin/env python3
import os
import platform
import subprocess
def detect_os() -> str:
system = platform.system().lower()
match system:
case "darwin":
return "macos"
case "freebsd":
return "freebsd"
case "windows":
return "windows"
case "linux":
# Check for specific Linux distributions
try:
with open("/etc/os-release") as f:
content = f.read()
if "ID=arch" in content:
return "arch"
if "ID=ubuntu" in content:
return "ubuntu"
except FileNotFoundError:
pass
return ""
# Main
target = detect_os()
config_path = os.path.expanduser(f"~/.config/fastfetch/{target}.jsonc")
if os.path.exists(config_path):
subprocess.run(["fastfetch", "-c", config_path])
else:
subprocess.run(["fastfetch"])