From fb4d83c4bf727d5e35ebf90c5aa2dc0c09a7c84a Mon Sep 17 00:00:00 2001 From: loseardes77 Date: Fri, 12 Apr 2024 08:13:30 +0000 Subject: [PATCH] Finished implementing hyprcursor build --- README.md | 4 ++-- edit-manifest.py | 23 +++++++++++++++++++++++ edit-meta.py | 25 +++++++++++++++++++++++++ hyprcursor-build.sh | 40 ++++++++++++++++++++++++++++++---------- 4 file(s) changed, 80 insertion(s)(+), 12 deletion(s)(-) diff --git a/README.md b/README.md --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ - [x] extract themes - [x] recolor svgs - [x] remove old png files -- [ ] edit mate.hl files to use svg -- [ ] compress the theme +- [x] edit mate.hl files to use svg +- [x] compress the theme ### How it works? diff --git a/edit-manifest.py b/edit-manifest.py new file mode 100644 --- /dev/null +++ b/edit-manifest.py @@ -0,0 +1,23 @@ +import sys + + +def main(): + args = sys.argv[1:] + metahl = args[0] + theme_name = args[1] + with open(metahl, 'r+') as f: + content = f.readlines() + f.seek(0) + f.truncate() + for line in content: + if not line.startswith("name = Extracted Theme") and not line.startswith("description = Automatically extracted with hyprcursor-util"): + f.write(line) + else: + if line.startswith("name = Extracted Theme"): + f.write("name = " + theme_name + "\n") + elif line.startswith("description = Automatically extracted with hyprcursor-util"): + f.write("description = Generated Bibata repository\n") + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/edit-meta.py b/edit-meta.py new file mode 100644 --- /dev/null +++ b/edit-meta.py @@ -0,0 +1,25 @@ +import sys + +def main(): + args = sys.argv[1:] + metahl = args[0] + svg_files = args[1:] + + with open(metahl, 'r+') as f: + content = f.readlines() + f.seek(0) + f.truncate() + has_written = False + for line in content: + if not line.startswith("define_size = "): + f.write(line) + elif not has_written: + content_to_write = "" + for svg_file in svg_files: + for svg in svg_file.split("\n"): + content_to_write += "define_size = 0, " + svg.split("/")[len(svg.split("/")) - 1] + "\n" + f.write(content_to_write) + has_written = True + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/hyprcursor-build.sh b/hyprcursor-build.sh --- a/hyprcursor-build.sh +++ b/hyprcursor-build.sh @@ -5,7 +5,6 @@ mkdir -p hyprcursor-build for theme in $(find ./themes -maxdepth 1 -type d | grep "Bibata-*"); do - theme_name=$(basename "$theme") hyprcursor-util --extract "$theme" --output "hyprcursor-build" done @@ -13,28 +12,49 @@ for theme in $(find ./hyprcursor-build -maxdepth 1 -type d | grep "extracted_Bibata-*"); do theme_name=$(basename "$theme") - for shape in $(find "$theme/hyprcursors" -maxdepth 2 -type d); do + theme_base=$(echo "$theme_name" | cut -d'_' -f2) + for shape in $(find "$theme/hyprcursors/" -maxdepth 1 -mindepth 1 -type d); do shape_name=$(basename "$shape") - svg_files=$(find "./hyprcursor-build/recolored_svgs/$theme_base" -name "$shape_name.svg" | grep "$shape_name") - theme_base=$(echo "$theme_name" | cut -d'_' -f2) + svg_files=$(find "./hyprcursor-build/recolored_svgs/$theme_base/" -name "$shape_name.svg" | grep "$shape_name") if [ -z "$svg_files" ]; then if [ "$shape_name" == "wait" ]; then svg_files=$(find "./hyprcursor-build/recolored_svgs/$theme_base/wait/" -name "*.svg") elif [ "$shape_name" == "left_ptr_watch" ]; then - svg_files=$(find "./hyprcursor-build/recolored_svgs/$theme_namebase/left_ptr_watch/" -name "*.svg") + svg_files=$(find "./hyprcursor-build/recolored_svgs/$theme_base/left_ptr_watch/" -name "*.svg") fi fi echo "$theme_base: $shape_name -> $svg_files" if [ -z "$svg_files" ]; then - echo "No SVG file found for $theme_base: $shape_name" + # echo "No SVG file found for $theme_base: $shape_name" exit 1 fi - rm -rf "$shape/*.png" - + png_files=$(find "$shape" -name "*.png") + for png_file in $png_files; do + rm "$png_file" + done + meta_file=$(find "$shape" -name "meta.hl") + python3 edit-meta.py "$meta_file" "$svg_files" for svg_file in $svg_files; do mv "$svg_file" "$shape" done - # TODO: edit the meta.hl files done -done \ No newline at end of file +done + +for theme in $(find ./hyprcursor-build/ -maxdepth 1 -type d | grep "extracted_Bibata-*"); do + manifest_file=$(find "$theme" -name "manifest.hl") + python3 edit-manifest.py "$manifest_file" "$(basename "$theme" | cut -d'_' -f2)" + hyprcursor-util --create "$theme" --output "hyprcursor-build" +done + +cd hyprcursor-build +for compressed_theme in $(find . -maxdepth 1 -type d | grep "theme_Bibata-*"); do + echo "Compressing $compressed_theme" + + tar -cJvf "hypr_$(basename "$compressed_theme"| cut -d'_' -f2).tar.xz" "$compressed_theme/" +done +cd .. + + + +mv hyprcursor-build/*.tar.xz bin/ \ No newline at end of file -- tangled.sh