File indexing completed on 2024-04-21 03:55:55

0001 #!/usr/bin/env bash
0002 
0003 SRC_DIR="src/"
0004 BREEZEICONS_DIR="breeze-icons"
0005 ICONS_SIZES=(48 32 22)
0006 TAB="    "
0007 
0008 kirigami_dir="$(cd $(dirname $(readlink -f $0))/.. && pwd)"
0009 
0010 case $1 in
0011 -h|--help)
0012         echo "usage: $(basename $0)"
0013         exit 1
0014         ;;
0015 esac
0016 
0017 if [[ ! -d ${kirigami_dir}/${BREEZEICONS_DIR} ]]; then
0018         echo "could not find ${BREEZEICONS_DIR}, please clone breeze-icons first into ${BREEZEICONS_DIR}:"
0019         echo "cd ${kirigami_dir} && git clone --depth 1 https://invent.kde.org/frameworks/breeze-icons.git ${BREEZEICONS_DIR}"
0020         exit 1
0021 fi
0022 
0023 pushd ${kirigami_dir} > /dev/null
0024 
0025 # find strings associated to variable with 'icon' in name and put them into an array
0026 if [[ -n $(which ag 2>/dev/null) ]]; then
0027         possible_icons=($(ag --ignore Icon.qml --file-search-regex "\.qml" --only-matching --nonumbers --noheading --nofilename "icon.*\".+\"" ${SRC_DIR} | egrep -o "*\".+\""))
0028         # try to find in Icon { ... source: "xyz" ... }
0029         possible_icons+=($(ag --ignore Icon.qml --file-search-regex "\.qml" -A 15 "Icon\s*{" ${SRC_DIR} | egrep "source:" | egrep -o "*\".+\""))
0030 else
0031         possible_icons=($(find ${SRC_DIR} -name "*.qml" -and -not -name "Icon.qml" -exec egrep "icon.*\".+\"" {} \; | egrep -o "*\".+\""))
0032 fi
0033 
0034 # sort array and filter out all entry which are not a string ("...")
0035 IFS=$'\n' icons=($(sort -u <<<"${possible_icons[*]}" | egrep -o "*\".+\"" | sed 's/\"//g'))
0036 unset IFS
0037 
0038 #printf "%s\n" "${icons[@]}"
0039 
0040 # generate .qrc
0041 echo "<RCC>"
0042 echo "${TAB}<qresource prefix=\"/\">"
0043 
0044 for icon in ${icons[@]}; do
0045         for size in ${ICONS_SIZES[@]}; do
0046                 file=$(find breeze-icons/icons/*/${size}/ -name "${icon}.*" -print -quit)
0047 
0048                 if [[ -n ${file} ]]; then
0049                         echo -e "${TAB}${TAB}<file alias=\"icons/$(basename ${file})\">${file}</file>"
0050                         #echo ${file}
0051                         break
0052                 fi
0053         done
0054 done
0055 
0056 echo "${TAB}</qresource>"
0057 echo "</RCC>"
0058 
0059 popd > /dev/null