#!/bin/bash

set -x
set -e
set -o pipefail
set -o errtrace

if ! test -d "$1" && ! test -f "$1" ; then
   true "ERROR: not a folder or file: $1"
   exit 1
fi

opts="\
   --exclude SC2086 \
   --exclude SC2086 \
   --exclude SC2016 \
   --exclude SC2034 \
   --exclude SC2129 \
   --exclude SC2004 \
   --exclude SC2088 \
   --exclude SC2015 \
   --exclude SC2068 \
   --exclude SC2001 \
   "

for file_name in $(find "$1" -type f -not -iwholename '*.git*' -not -iwholename '*changelog.upstream*'); do
   true "file_name: $file_name"
   if ! test -f "$file_name" ; then
      continue
   fi
   if ! grep '#!/bin/bash' "$file_name" ; then
      continue
   fi
   if shellcheck $opts "$file_name" ; then
      continue
   fi
   file_name_short="${file_name##*/}"
   true "press y to open kate. enter to continue"
   read temp
   if test "$temp" = "y" ; then
      kate "$file_name" >/dev/null 2>&1
   fi
done

true "INFO: End."
