aboutsummaryrefslogtreecommitdiffstats
path: root/config/hypr/scripts/LuaAutoReload.sh
blob: 4a9d50400ae7e56f0c6711c77fd242b6df3bfaef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
# ==================================================
#  KoolDots (2026)
#  Project URL: https://github.com/LinuxBeginnings
#  License: GNU GPLv3
#  SPDX-License-Identifier: GPL-3.0-or-later
# ==================================================
# Auto-reload Hyprland when Lua config files change.

set -euo pipefail

watch_root="$HOME/.config/hypr"
[ -d "$watch_root" ] || exit 0

reload_hypr() {
  hyprctl reload >/dev/null 2>&1 || true
}

if command -v inotifywait >/dev/null 2>&1; then
  debounce_and_reload() {
    sleep 0.2
    while inotifywait -q -t 0.2 -e close_write,create,move,delete -r --include '(^|/)[^/]+\.lua$' "$watch_root" >/dev/null 2>&1; do
      :
    done
    reload_hypr
  }

  inotifywait -m -q -r -e close_write,create,move,delete --include '(^|/)[^/]+\.lua$' "$watch_root" | while read -r _; do
    debounce_and_reload
  done
  exit 0
fi

# Fallback polling path when inotify-tools isn't installed.
snapshot() {
  find "$watch_root" -type f -name '*.lua' -printf '%p:%T@\n' 2>/dev/null | LC_ALL=C sort
}

previous_state="$(snapshot)"
while true; do
  sleep 1
  current_state="$(snapshot)"
  if [ "$current_state" != "$previous_state" ]; then
    previous_state="$current_state"
    reload_hypr
  fi
done
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage