Files
dotfiles/dotfiles/config/taffybar/scripts/taffybar-restart

31 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
pkill -u "$USER" -x taffybar || true
cd "$root"
# Hyprland can restart and change the instance signature, leaving old shells with
# a stale HYPRLAND_INSTANCE_SIGNATURE. Fix it before launching taffybar so any
# `hyprctl` calls inside the bar work.
if command -v hyprctl >/dev/null 2>&1 && command -v jq >/dev/null 2>&1; then
if ! hyprctl monitors -j >/dev/null 2>&1; then
instances_json="$(hyprctl instances -j 2>/dev/null || true)"
if [[ -n "${WAYLAND_DISPLAY:-}" ]]; then
inst="$(printf '%s\n' "$instances_json" | jq -r --arg sock "$WAYLAND_DISPLAY" '.[] | select(.wl_socket == $sock) | .instance' 2>/dev/null | head -n1 || true)"
else
inst="$(printf '%s\n' "$instances_json" | jq -r '.[0].instance // empty' 2>/dev/null || true)"
fi
if [[ -n "${inst:-}" ]]; then
export HYPRLAND_INSTANCE_SIGNATURE="$inst"
fi
fi
fi
setsid -f direnv exec . cabal run >/tmp/taffybar.log 2>&1
echo "Started taffybar in the background. Logs: /tmp/taffybar.log"