#!/bin/bash
#args=("$@")
args=()
while [[ $# -gt 0 ]]; do
  case $1 in
    -h|--help)
      echo "
sumake:
  -h, --help: show this help
  -v, --version: show version
  --zsh-init: init zsh completion
      "
      args+=("$1")
      ;;
    -v|--version)
      echo "sumake: {VERSION}"
      args+=("$1")
      ;;
    --zsh-init)
append_content=$(cat <<EOF
# sumake zsh completion
autoload -U compinit
compinit
_sumake() {{
_make "\$@"
}}
compdef _sumake sumake
zstyle ':completion::complete:sumake:*:targets' call-command true
EOF
)
if ! grep -q "# sumake zsh completion" ~/.zshrc ; then
  echo "$append_content" >> ~/.zshrc
  echo "zsh completion init done"
else
  echo "zsh completion already init"
fi

      exit 0
      ;;
    *)
      args+=("$1")
      ;;
  esac
  shift
done


cmd="make -f {UTILS_MK}"
if [ -f Makefile ]; then
  cmd+=" -f Makefile "
fi
$cmd "${{args[@]}}"


