From a49140512fc252f636179e1b939900587588f1f2 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Thu, 5 Dec 2024 01:28:46 +0100 Subject: [PATCH] Make a more generic generate_qrc script --- generate_images_qrc.sh | 23 ----------------------- generate_qrc.sh | 38 ++++++++++++++++++++++++++++++++++++++ images.qrc | 1 - 3 files changed, 38 insertions(+), 24 deletions(-) delete mode 100755 generate_images_qrc.sh create mode 100755 generate_qrc.sh diff --git a/generate_images_qrc.sh b/generate_images_qrc.sh deleted file mode 100755 index 55a5b3d..0000000 --- a/generate_images_qrc.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -set -euo pipefail - -QRC="images.qrc" -IMG_DIR="img" - -cat <"$QRC" - - - -EOF - -find "$IMG_DIR" -type f | while IFS= read -r file; do - printf " %s\n" "$file" >>"$QRC" -done - -cat <>"$QRC" - - - - -EOF diff --git a/generate_qrc.sh b/generate_qrc.sh new file mode 100755 index 0000000..983dc41 --- /dev/null +++ b/generate_qrc.sh @@ -0,0 +1,38 @@ +#!/bin/bash +set -euo pipefail + +CUR_DIR="$(dirname "$0")" + +# Function to generate a .qrc file for a given directory and file extension +generate_qrc() { + local dir=$1 + local qrc_file=$2 + local pattern=$3 + + # Start the QRC file + cat <"$qrc_file" + + + +EOF + + # Find all files with the given extension in the directory and add them to the QRC file + find "$dir" -type f -name "$pattern" | while IFS= read -r file; do + printf " %s\n" "$file" >>"$qrc_file" + done + + # End the QRC file + cat <>"$qrc_file" + + +EOF + + # Split this to avoid vim interpreting this file as xml + echo -n "" >>"$qrc_file" +} + +pushd "$CUR_DIR" >/dev/null +generate_qrc "img" "images.qrc" "*.svg" +popd >/dev/null diff --git a/images.qrc b/images.qrc index 5dd87e4..c3d1781 100644 --- a/images.qrc +++ b/images.qrc @@ -69,6 +69,5 @@ img/playing_cards/fronts/spades_queen.svg -