#!/bin/env sh

HYPRDROP_GIT_PATH="$HOME/.cache/hyprdrop"

install_hyprdrop() {
  PREV_DIRECTORY=$PWD

  if [ ! -d "$HYPRDROP_GIT_PATH" ]; then
    git clone https://github.com/kjlo/hyprdrop "$HYPRDROP_GIT_PATH"
  fi

  cd ~/.cache/hyprdrop
  cargo install --path .

  cd $PREV_DIRECTORY
}

check_hyprdrop() {
  if [ ! -d "$HOME/.cache/hyprdrop" ]; then
    return 0
  fi

  PREV_DIRECTORY=$PWD

  cd $HYPRDROP_GIT_PATH

  if ! git remote update && git status | grep behind >>/dev/null; then
    cd $PREV_DIRECTORY
    return 0
  fi

  return 1
}

if check_hyprdrop; then
  addActions install_hyprdrop
fi
