#!/bin/bash

# Script to change label size in a element collection tree.
# by Morgan Leijström, copyleft, and no guarantees, make backup and think twice before running it as root

#   Define base of tree to go down into (or single specific file)

# Alternative 1: local compile QET elements path
# /!\ need to be run as root do do this
# /!\  CAUTION /!\
# basedir=/usr/local/share/qelectrotech/elements/

# Alternative 2: Testing...
basedir=~/.qet/elements-test

# Alternative 3: Your own collection /!\  CAUTION /!\ take backup first...
# basedir=~/.qet/elements-test

# Alternative 3: You could also run it before compiling / installing QETm in its source subdir elements as basedir
# basedir=elements

#    *** Pseudocode ***
#
# in the element collection tree ;
#  search every .elmt file ;
#    only on line containing 'tagg="label"' ;
#       replace 'size="ANY"' with 'size="NEW"'  Where ANY mean any number (any digit(s)!), NEW is new value

newsize=9  # QElectroTech collection use size 9

find $basedir -name "*.elmt" -print0 | xargs --null sed -i "/tagg=\"label\"/ s/size=\"[[:digit:]]*\"/size=\"$newsize\"/"

# Notes:
# the -print0 makes find export dirnames with spaces better, --null makes sed work with spaces in filenames
# the " in search and replace strings are escaped with \
# to work on MAC add two single quote characters after -i (with space before and after them but nothing between them)

#  CHANGING LABEL SIZES IN A .QET PROJECT FILE
# Example: set all labels to size 8, in a new file:
# sed "/tagg=\"label\"/ s/size=\"[[:digit:]]*\"/size=\"8\"/g" originalproject.qet > modifiedproject.qet
