# Hooks Hooks are custom scripts that run at specific points during sync and restore operations. Use them to reload services, validate configs, or run any automation you need. ## Setup Create the hooks directory and add executable scripts: ```bash mkdir -p ~/.config/synx/hooks ``` ## Available Hooks | Hook file | Runs when | Description | |-----------|-----------|-------------| | `pre-sync` | Before starting the sync step (backing up system to `synx` dir). | Useful to clear caches, dump package lists, or generate dynamic configs before backup. | | `post-sync` | After the sync finishes successfully. | Useful to commit changes to git, or push to a remote repository automatically. | | `pre-restore` | Before restoring files from `synx` back to the system. | Pre-flight checks or backing up current system state just in case. | | `post-restore` | After restore finishes. | Reloading specific UI elements, restarting systemd services, or triggering specific scripts. | | `pre-profile` | Before applying a profile (before syncing the old state). Receives the target profile name as `$1`. | Checking requirements for the specific profile, or taking backups. | | `post-profile` | After applying a profile. Receives the target profile name as `$1`. | Applying profile-specific themes, enabling/disabling Hyprland plugins, etc. | ## Behavior - **Missing hook** → silently skipped (no error) - **Not executable** → prints a warning: `chmod +x` it - **Pre-hook fails** (non-zero exit) → aborts the operation - **Post-hook fails** → warns but doesn't undo anything - Scripts run with your terminal's stdin/stdout attached ## Examples ### Restart Waybar after restore ```bash cat > ~/.config/synx/hooks/post-restore << 'EOF' #!/bin/bash if pgrep -x waybar > /dev/null; then pkill waybar sleep 0.5 waybar &disown echo "Waybar restarted" fi EOF chmod +x ~/.config/synx/hooks/post-restore ``` ### Validate configs before sync ```bash cat > ~/.config/synx/hooks/pre-sync << 'EOF' #!/bin/bash echo "Checking Hyprland config..." if ! hyprctl reload 2>/dev/null; then echo "WARNING: Hyprland config may have errors" fi EOF chmod +x ~/.config/synx/hooks/pre-sync ``` ### Notify on sync completion ```bash cat > ~/.config/synx/hooks/post-sync << 'EOF' #!/bin/bash notify-send "Synx" "Dotfiles synced successfully" -i dialog-information EOF chmod +x ~/.config/synx/hooks/post-sync ``` ### Source fish config after restore ```bash cat > ~/.config/synx/hooks/post-restore << 'EOF' #!/bin/bash if command -v fish &> /dev/null; then fish -c "source ~/.config/fish/config.fish" 2>/dev/null echo "Fish config reloaded" fi EOF chmod +x ~/.config/synx/hooks/post-restore ``` ## Notes - Hook scripts can be written in any language (bash, python, fish, etc.) — just set the appropriate shebang - Hooks run from the current working directory, not from any specific path - Keep hooks fast — they run synchronously and block the sync/restore operation