#!/bin/bash

### (1) mosi hikisuu ga areba, suguni jikkou
if [ $# -eq 1 ] ; then
  file=$1
  echo "compile ${file}"
  cp ${file} TestBuild/TestBuild.ino
  cd TestBuild
  ./compile.sh && ./upload.sh && ./monitor.sh
  cd ..
  exit
fi

### (2) hikisuu ga nakereba, list and select

ary=()

for i in *.ino ; do
  ary+=("$i")
done

for i in ${!ary[@]} ; do
  echo "$i : ${ary[$i]}"
done

echo -n "Input num for build&upload (q:quit) > "
read input

if [[ "$input" == "q" ]]; then
  exit
fi

if [ -n "${ary[$input]}" ]; then
  echo "$input : ${ary[$input]}"
  file=${ary[$input]}
  cp ${file} TestBuild/TestBuild.ino
  cd TestBuild
  ./compile.sh && ./upload.sh && ./monitor.sh
  cd .. 
else
  echo "Sorry, ${input} is not found."
fi



