aboutsummaryrefslogtreecommitdiffstats
path: root/config/hypr/scripts/LuaAutoReload.sh
blob: 128c1fc9269af297248e17439006792a35d5b93e (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/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="${XDG_CONFIG_HOME:-$HOME/.config}/hypr"
[ -d "$watch_root" ] || exit 0
session="${HYPRLAND_INSTANCE_SIGNATURE:-default}"
pid_file="/tmp/hypr-lua-autoreload-${session}.pid"

if [ -f "$pid_file" ]; then
  existing_pid="$(cat "$pid_file" 2>/dev/null || true)"
  if [ -n "$existing_pid" ] && kill -0 "$existing_pid" 2>/dev/null; then
    exit 0
  fi
fi

echo "$$" >"$pid_file"
cleanup() {
  rm -f "$pid_file"
}
trap cleanup EXIT INT TERM

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