#!/usr/bin/env bash
# Installs and configures the Notify desktop plugin for Omarchy.
set -euo pipefail
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
plugin_src="$script_dir/notify.desktop"
omarchy_plugins_dir="$HOME/.config/omarchy/plugins"
plugin_target="$omarchy_plugins_dir/notify.desktop"
notify_config_dir="$HOME/.config/notify"
config_file="$script_dir/notify.json"
echo "==> Installing Notify plugin for Omarchy..."
if [ ! -d "$plugin_src" ]; then
echo "Error: notify.desktop plugin directory not found in $script_dir" >&2
exit 1
fi
mkdir -p "$omarchy_plugins_dir"
# When developing in git repository, prefer symlink unless --copy is specified
if [ -d "$script_dir/../.git" ] && [ "${1:-}" != "--copy" ]; then
ln -sfn "$plugin_src" "$plugin_target"
echo "โ Linked plugin files: $plugin_target -> $plugin_src"
else
if [ -L "$plugin_target" ] || [ -d "$plugin_target" ]; then
rm -rf "$plugin_target"
fi
cp -r "$plugin_src" "$plugin_target"
echo "โ Installed plugin files to $plugin_target"
fi
# Install pre-configured notify.json if present
if [ -f "$config_file" ]; then
mkdir -p "$notify_config_dir"
if [ -f "$notify_config_dir/notify.json" ]; then
bak="$notify_config_dir/notify.json.bak.$(date +%s)"
cp "$notify_config_dir/notify.json" "$bak"
echo " (Backed up existing config to $bak)"
fi
cp "$config_file" "$notify_config_dir/notify.json"
echo "โ Installed configuration to $notify_config_dir/notify.json"
fi
# Reload and enable plugin in Omarchy
if command -v omarchy-restart-shell >/dev/null 2>&1; then
echo "==> Restarting Omarchy shell..."
omarchy-restart-shell >/dev/null 2>&1 || true
elif command -v omarchy-shell >/dev/null 2>&1; then
echo "==> Rescanning Omarchy shell plugins..."
omarchy-shell shell rescanPlugins 2>/dev/null || true
fi
if command -v omarchy >/dev/null 2>&1; then
echo "==> Enabling plugin in Omarchy..."
omarchy plugin enable notify.desktop 2>/dev/null || true
fi
echo "๐ Notify plugin installed and configured successfully!"