Transcode duplicate test to python

This commit is contained in:
Ryan Delaney 2023-11-24 11:41:25 -05:00
parent 470d5a5c08
commit 2da9e2e32c
2 changed files with 26 additions and 8 deletions

26
tests/find_dupes Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env python3
#
"""Check the compiled lscolors.sh file for duplicate extensions."""
import sys
import re
from collections import Counter
def main() -> int:
with open("../lscolors.sh", "r") as f:
data = next(f)
extensions = re.findall(r"\*\.(.*?)=", data)
if duplicates := [ext for ext, count in Counter(extensions) if count > 1]:
print(f"Duplicates found: {', '.join(duplicates)}")
return 1
else:
print("No duplicates found.")
return 0
if __name__ == "__main__":
sys.exit(main())
# EOF

View File

@ -1,8 +0,0 @@
#!/usr/bin/env bash
#
exts="$(dircolors LS_COLORS | head -n1 | sed 's/=[^:]*//g ; s/:/\n/g')"
exts_sorted="$(sort <<< "$exts")"
exts_uniq="$(sort -u <<< "$exts")"
diff --color=auto --text --report-identical-files <(echo "$exts_uniq") <(echo "$exts_sorted")