#!/bin/zsh
function zsh_add_config() {
  [ -f "$ZDOTDIR/$1" ] && ! [ -L "$ZDOTDIR/$1" ] && source "$ZDOTDIR/$1"
}

function zsh_add_plugin() {
  PLUGIN_NAME=$(echo $1 | cut -d"/" -f2)
  if ! [ -d "$ZDOTDIR/plugins/$PLUGIN_NAME" ]; then
    git clone "https://github.com/$1.git" "$ZDOTDIR/plugins/$PLUGIN_NAME"
  fi
  zsh_add_config "plugins/$PLUGIN_NAME/$PLUGIN_NAME.plugin.zsh"
  zsh_add_config "plugins/$PLUGIN_NAME/$PLUGIN_NAME.zsh"
  zsh_add_config "plugins/$PLUGIN_NAME/async"
  zsh_add_config "plugins/$PLUGIN_NAME/nix.plugin.zsh"
}

function zsh_fpath_plugin() {
  PLUGIN_NAME=$(echo $1 | cut -d"/" -f2)
  if ! [ -d "$ZDOTDIR/plugins/$PLUGIN_NAME" ]; then
    git clone "https://github.com/$1.git" "$ZDOTDIR/plugins/$PLUGIN_NAME"
  fi
  fpath+=($ZDOTDIR/plugins/$PLUGIN_NAME)
}
