Files
dotfiles/.config/fastfetch/detect_os.py

36 lines
935 B
Python

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"])