1
1
#! /usr/bin/env bash
2
2
3
- # idmerge.sh: read esphome yaml and output merged esphome yaml.
3
+ # idmerge.sh: merge yaml common blocks with an id: tag
4
4
5
5
# Common blocks are merged backwards in the output by referencing tags
6
6
# specified in "id: <tag>" yaml lines. The first common block to
13
13
# Usage: idmerge.sh -id <idTag> <input.yaml >output.yaml
14
14
15
15
# After running idmerge.sh, it is advised to postprocess the yaml with
16
- # awk '/^[[:alnum:]_]/{print "---"} | yq '... comments=""' esphome .yaml
16
+ # awk '/^[[:alnum:]_]/{print "---"} | yq '... comments=""' file .yaml
17
17
# before piping it into yq to merge sections using:
18
18
19
19
# yq eval-all '. as $item ireduce ({}; . *+ $item)'
26
26
# Require all variables to be declared - to catch variable typos early.
27
27
28
28
declare -r me=${0##*/ } # basename of this script
29
- declare -r usage=" $me : read yaml and output merged yaml using an id tag.
29
+ declare -r usage=" $me : merge yaml common blocks with an id: tag
30
30
31
31
Usage: $me : [-q] [-p] [-m] [-h] [-t tag] [-o outfile] <file.yaml>\n
32
32
-t|--tag\tItem tag that uniquely names what to merge. Defaults to " id" .
@@ -124,7 +124,7 @@ declare -a -i block_from # block first line number
124
124
declare -a -i block_to # block last line number
125
125
declare -a -i block_idline # block "id:" line if it has one, else zero
126
126
127
- # These read-only strings are used to identify special esphome yaml lines.
127
+ # These read-only strings are used to identify special yaml lines.
128
128
129
129
declare -r newdoc=" ---"
130
130
declare -r is_array=' ^[[:blank:]]*- ([[:alnum:]: _]+)[[:blank:]]*$'
@@ -135,7 +135,7 @@ declare -r is_comment='^[[:blank:]]*#.*$'
135
135
declare -r is_blank=' ^[[:blank:]]*$'
136
136
declare -r get_mapname=' ^([[:alnum:]_]+):.*$'
137
137
138
- # This function reads in esphome yaml on stdin.
138
+ # This function reads in yaml on stdin.
139
139
140
140
read_lines () {
141
141
declare -i n=0
0 commit comments