shell: format with shfmt

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I86a7c52c32a14bf0a1184b6d7dc50112c49ade91
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..2fb4fc6
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,6 @@
+# Config for shfmt
+[{*.sh,tools/sdbus++-gen*}]
+indent_style = space
+indent_size = 4
+switch_case_indent = true
+space_redirects = true
diff --git a/tools/sdbus++-gen-meson b/tools/sdbus++-gen-meson
index 8a3ddf3..8a05db7 100755
--- a/tools/sdbus++-gen-meson
+++ b/tools/sdbus++-gen-meson
@@ -8,7 +8,7 @@
 
 function show_usage {
     cat \
-<<EOF
+        << EOF
 Usage: $(basename "$0") [options] <command-args>*
 
 Generate meson.build files from a directory tree containing YAML files and
@@ -51,8 +51,7 @@
 options="$(getopt -o hc:d:o:t:v --long help,command:,directory:,output:,tool:,version -- "$@")"
 eval set -- "$options"
 
-while true;
-do
+while true; do
     case "$1" in
         -h | --help)
             show_usage
@@ -110,7 +109,7 @@
     meson_empty_file "$outputdir"
 
     cat >> "$outputdir/meson.build" \
-<<EOF
+        << EOF
 sdbuspp_gen_meson_ver = run_command(
     sdbuspp_gen_meson_prog,
     '--version',
@@ -143,14 +142,12 @@
     prev_meson_path=""
 
     # Split the path into segments.
-    for part in $(echo "$1" | tr '/' '\n');
-    do
+    for part in $(echo "$1" | tr '/' '\n'); do
         prev_meson_path="$meson_path"
         meson_path="$meson_path/$part"
 
         # Create the meson.build for this segment if it doesn't already exist.
-        if [ "" == "${meson_paths[$meson_path]}" ];
-        then
+        if [ "" == "${meson_paths[$meson_path]}" ]; then
             meson_paths["$meson_path"]="1"
             meson_empty_file "$meson_path"
 
@@ -158,8 +155,7 @@
             # We need to skip adding the links into the 'root' meson.build
             # because most repositories want to selectively add TLDs based
             # on config flags.  Let them figure out their own logic for that.
-            if [ "$outputdir" != "$prev_meson_path" ];
-            then
+            if [ "$outputdir" != "$prev_meson_path" ]; then
                 echo "subdir('$part')" >> "$prev_meson_path/meson.build"
             fi
         fi
@@ -177,9 +173,8 @@
     # Determine the source and output files based on the YAMLs present.
     sources=""
     outputs=""
-    for s in ${interfaces[$1]};
-    do
-      sources="'$yamldir/$1.$s', "
+    for s in ${interfaces[$1]}; do
+        sources="'$yamldir/$1.$s', "
 
         case "$s" in
             errors.yaml)
@@ -195,7 +190,7 @@
 
     # Create the target to generate the 'outputs'.
     cat >> "$mesondir/meson.build" \
-<<EOF
+        << EOF
 generated_sources += custom_target(
     '$1__cpp'.underscorify(),
     input: [ $sources ],
@@ -220,14 +215,13 @@
 
     # Determine the source files based on the YAMLs present.
     sources=""
-    for s in ${interfaces[$1]};
-    do
+    for s in ${interfaces[$1]}; do
         sources="'$yamldir/$1.$s', "
     done
 
     # Create the target to generate the interface.md file.
     cat >> "$mesondir/meson.build" \
-<<EOF
+        << EOF
 generated_others += custom_target(
     '$1__markdown'.underscorify(),
     input: [ $sources ],
@@ -250,11 +244,9 @@
     yamls=""
 
     # Find all the YAML files in the TLD subdirectories.
-    for d in $TLDs;
-    do
+    for d in $TLDs; do
         dir="$rootdir/$d"
-        if [ ! -d "$dir" ];
-        then
+        if [ ! -d "$dir" ]; then
             continue
         fi
 
@@ -268,21 +260,19 @@
     yamls="$(echo "$yamls" | tr " " "\n" | sort)"
 
     # Assign the YAML files into the hash-table by interface name.
-    for y in $yamls;
-    do
+    for y in $yamls; do
         rel="$(realpath "--relative-to=$rootdir" "$y")"
         dir="$(dirname "$rel")"
         ext="${rel#*.}"
         base="$(basename "$rel" ".$ext")"
 
-        interfaces["$dir/$base"]="${interfaces[$dir/$base]} $ext"
+        interfaces["$dir/$base"]="${interfaces[dir / base]} $ext"
     done
 
     # Create the meson.build files.
     meson_create_root
     sorted_ifaces="$(echo "${!interfaces[@]}" | tr " " "\n" | sort)"
-    for i in ${sorted_ifaces};
-    do
+    for i in ${sorted_ifaces}; do
         meson_create_path "$i"
         meson_cpp_target "$i"
         meson_md_target "$i"
@@ -295,15 +285,13 @@
 ## For an interface foo/bar, the outputdir is expected to be foo/bar.
 function cmd_cpp {
 
-    if [ "" == "$1" ];
-    then
+    if [ "" == "$1" ]; then
         show_usage
         exit 1
     fi
 
-    if [ ! -e "$rootdir/$1.interface.yaml" ] && \
-        [ ! -e "$rootdir/$1.errors.yaml" ];
-    then
+    if [ ! -e "$rootdir/$1.interface.yaml" ] &&
+        [ ! -e "$rootdir/$1.errors.yaml" ]; then
         echo "Missing YAML for $1."
         exit 1
     fi
@@ -313,15 +301,13 @@
     sdbusppcmd="$sdbuspp -r $rootdir"
     intf="${1//\//.}"
 
-    if [ -e "$rootdir/$1.interface.yaml" ];
-    then
+    if [ -e "$rootdir/$1.interface.yaml" ]; then
         $sdbusppcmd interface server-header "$intf" > "$outputdir/server.hpp"
         $sdbusppcmd interface server-cpp "$intf" > "$outputdir/server.cpp"
         $sdbusppcmd interface client-header "$intf" > "$outputdir/client.hpp"
     fi
 
-    if [ -e "$rootdir/$1.errors.yaml" ];
-    then
+    if [ -e "$rootdir/$1.errors.yaml" ]; then
         $sdbusppcmd error exception-header "$intf" > "$outputdir/error.hpp"
         $sdbusppcmd error exception-cpp "$intf" > "$outputdir/error.cpp"
     fi
@@ -333,15 +319,13 @@
 ## For an interface foo/bar, the outputdir is expected to be foo.
 function cmd_markdown {
 
-    if [ "" == "$1" ];
-    then
+    if [ "" == "$1" ]; then
         show_usage
         exit 1
     fi
 
-    if [ ! -e "$rootdir/$1.interface.yaml" ] && \
-        [ ! -e "$rootdir/$1.errors.yaml" ];
-    then
+    if [ ! -e "$rootdir/$1.interface.yaml" ] &&
+        [ ! -e "$rootdir/$1.errors.yaml" ]; then
         echo "Missing YAML for $1."
         exit 1
     fi
@@ -353,13 +337,11 @@
     base="$(basename "$1")"
 
     echo -n > "$outputdir/$base.md"
-    if [ -e "$rootdir/$1.interface.yaml" ];
-    then
+    if [ -e "$rootdir/$1.interface.yaml" ]; then
         $sdbusppcmd interface markdown "$intf" >> "$outputdir/$base.md"
     fi
 
-    if [ -e "$rootdir/$1.errors.yaml" ];
-    then
+    if [ -e "$rootdir/$1.errors.yaml" ]; then
         $sdbusppcmd error markdown "$intf" >> "$outputdir/$base.md"
     fi
 }
diff --git a/tools/sdbus++-gendir b/tools/sdbus++-gendir
index 25c4c0e..2ad4e36 100755
--- a/tools/sdbus++-gendir
+++ b/tools/sdbus++-gendir
@@ -32,8 +32,7 @@
 options="$(getopt -o ho:t:j: --long help,list-all,output:,tool:,jobs: -- "$@")"
 eval set -- "$options"
 
-while true;
-do
+while true; do
     case "$1" in
         -h | --help)
             show_usage
@@ -70,8 +69,7 @@
     esac
 done
 
-if [ $# -eq 0 ];
-then
+if [ $# -eq 0 ]; then
     show_usage
     exit 1
 fi
@@ -87,11 +85,9 @@
 #   $5: 'append-mode' if present.
 function generate_single {
 
-    if [ "xempty" == "x$1" ];
-    then
+    if [ "empty" == "$1" ]; then
         echo -n > "$outputdir/$4"
-    elif [ "x" == "x$5" ];
-    then
+    elif [ "" == "$5" ]; then
         $sdbuspp "$1" "$2" "$3" > "$outputdir/$4" &
         all_jobs="$all_jobs $!"
     else
@@ -101,8 +97,7 @@
 
     # Emit filename as needed.
     filename=$outputdir/$4
-    if [ "x1" != "x${emitted_file_names[$filename]}" ];
-    then
+    if [ "x1" != "x${emitted_file_names[$filename]}" ]; then
         emitted_file_names[$filename]="1"
 
         # Always emit generated file name for foo-cpp and foo-header.
@@ -113,8 +108,7 @@
                 ;;
 
             *)
-                if [ "xyes" == "x$listall" ];
-                then
+                if [ "yes" == "$listall" ]; then
                     echo "$filename"
                 fi
                 ;;
@@ -123,22 +117,19 @@
 
     # Ensure that no more than ${parallel} jobs are running at a time and if so
     # wait for them to finish.
-    if [[ $(echo "$all_jobs" | wc -w) -ge $parallel ]];
-    then
+    if [[ $(echo "$all_jobs" | wc -w) -ge $parallel ]]; then
         waitall
     fi
 }
 
 function waitall {
-    for job in $all_jobs;
-    do
+    for job in $all_jobs; do
         wait "$job"
     done
     all_jobs=""
 }
 
-for d in "$@";
-do
+for d in "$@"; do
     interfaces="$(find "$d" -name '*.interface.yaml')"
     errors="$(find "$d" -name '*.errors.yaml')"
 
@@ -146,8 +137,7 @@
     # which YAML sources are present.  For these files, we need to first
     # create an empty file to ensure the file does not carry old data from
     # a previous run.
-    for y in $interfaces $errors;
-    do
+    for y in $interfaces $errors; do
         path="${y%.interface.yaml}"
         path="${path%.errors.yaml}"
         iface="${path//\//.}"
@@ -156,8 +146,7 @@
         generate_single empty markdown "$iface" "$path.md"
     done
 
-    for i in $interfaces;
-    do
+    for i in $interfaces; do
         path="${i%.interface.yaml}"
         iface="${path//\//.}"
 
@@ -169,9 +158,7 @@
     done
     waitall # finish all before continuing
 
-
-    for e in $errors;
-    do
+    for e in $errors; do
         path="${e%.errors.yaml}"
         iface="${path//\//.}"