#!/bin/bash

if ! updates_arch=$(checkupdates 2> /dev/null | wc -l ); then
  updates_arch=0
fi

if ! updates_aur=$(trizen -Su --aur --quiet | wc -l); then
  updates_aur=0
fi

updates=$(("$updates_arch" + "$updates_aur"))

function check () {
  if [[ $updates -gt 0 ]]; then
    printf '󰻍'
  else
    printf '󰳈'
  fi
}

function count () {
  printf '%s Update(s)' "$updates"
}

function install () {
  echo "Starting install updates"
  echo ""

  yay

  notify-send "Update complete"
}

if [[ $1 == "--check" ]]; then
  check
elif [[ $1 == "--install" ]]; then 
  install
elif [[ $1 == "--count" ]]; then 
  count
fi
