#!/usr/bin/env nix-shell #!nix-shell -i python3 -p python3 import re import subprocess from collections import defaultdict # nix-locate -r "share/(icons/hicolor/[^/]+/apps|pixmaps)/.*\.[^/]+" --all | awk '{print substr($4, length($4) - 3 + 1)}' | sort -u ICON_SUFFIXES = [ 'bmp', 'gif', 'icns' 'ico', 'jpeg', 'jpg', 'png', 'svg', 'svgz', 'xpm', ] ICON_SUFFIXES += [x.upper() for x in ICON_SUFFIXES] LOCATE_REGEX = f'share/(applications/[^/]+\\.desktop|pixmaps/[^/]+\\.({'|'.join(ICON_SUFFIXES)})|icons/hicolor/[^/]+/apps/[^/]+\\.({'|'.join(ICON_SUFFIXES)}))' result = subprocess.run(['nix-locate', '-r', LOCATE_REGEX, '--all'], capture_output=True) results = [] for x in result.stdout.split(b"\n"): try: drv, size, type, path = x.split() results.append({ 'drv': drv.decode(), 'size': size.decode(), 'type': type.decode(), 'path': path.decode(), }) except: pass results_by_package = defaultdict(list) for x in results: results_by_package[x['drv']].append({ 'size': x['size'], 'type': x['type'], 'path': x['path'], }) def ends_with_image_suffix(str) -> bool: return any(str.endswith(suf) for suf in ICON_SUFFIXES) results_by_package_without_icons = { } for drv, v in results_by_package.items(): if any(x['path'].endswith('.desktop') for x in v) and not any(ends_with_image_suffix(x['path']) for x in v): results_by_package_without_icons[drv] = v def print_result(drv, v): print(f"{drv}:") for x in v: p = re.sub(r'^/nix/store/[^/]+/', '', x['path']) print(f" {x['type']} {p} ({x['size']})") print("") for drv, v in results_by_package_without_icons.items(): print_result(drv, v) print(f'COUNT: {len(results_by_package_without_icons)}')