forge
Explore
Log in

Don't you dare go Hollow

Keep only the current line, no playback history

Browse files at this commit

ed96c9b6bf9cfd4a481a8e438aaade2758785d34Ahmet Kaan GümüşParent: ef264af
  • fix
    • keep only the current line, no playback history
Show full message
fix(song-detail): keep only the current line, no playback history

/tmp/song_detail_last accumulated every emitted line — 9454 lines in the
live file. That log was an emergent side effect of the append workaround,
not a feature, and the `cat` consumers rendered the whole blob.

The file now holds exactly the current line: writes truncate in place (the
inode never changes), nothing playing truncates it to 0 bytes, and startup
carries over at most one line so a leftover append-era log is dropped.

Consumers read the current line instead of following a stream: waybar
custom/music moved from `tail -n 1 -F` to `cat` + interval 1, the same
shape eww and hyprlock already use. tail -F needed the append stream to
deliver equal-length rewrites and printed "file truncated" on every
in-place rewrite; an interval read holds no offset state to go stale.

No history, no persistence: everything stays in tmpfs and is rebuilt from
playerctl each poll.
.config/scripts/shared/song_detail_writer.shmodified+21 -15
@@ -1,12 +1,15 @@
1 #!/bin/bash1 #!/bin/bash
2 # Single-source writer: poll playerctl, write the formatted song-detail line2 # Single-source writer: poll playerctl, write the formatted song-detail line
3-# to /tmp/song_detail_last so every waybar bar can stream it via `tail -F`3+# to /tmp/song_detail_last so every consumer (waybar, eww, hyprlock) reads it
4 # without two scripts racing on shared /tmp state.4 # without two scripts racing on shared /tmp state.
5 #5 #
6+# The file holds ONLY the current line: no history, no persistence. Every
7+# write truncates in place, so the inode stays put and readers that re-read
8+# the file each interval always see the live line. Whatever was in the file
9+# before — including a leftover in-place log from an older build — is dropped.
10+#
6 # niri spawn-at-startup re-runs on compositor restart and used to stack11 # niri spawn-at-startup re-runs on compositor restart and used to stack
7-# copies; orphans then `mv`-replaced the output inode every second, which12+# copies; newest instance takes over (singleton below).
8-# makes waybar's `tail -F` reopen and flicker. Newest instance takes over;
9-# the tailed file is rewritten in place so its inode stays put.
10 13
11 OUTPUT_FILE="/tmp/song_detail_last"14 OUTPUT_FILE="/tmp/song_detail_last"
12 POSITION_CACHE_PREFIX="/tmp/playerctl_position_cache_"15 POSITION_CACHE_PREFIX="/tmp/playerctl_position_cache_"
@@ -46,12 +49,15 @@ atomic_write() {
46 printf '%s\n' "$content" > "$tmp" && mv -f "$tmp" "$target"49 printf '%s\n' "$content" > "$tmp" && mv -f "$tmp" "$target"
47 }50 }
48 51
49-# Append-only stream. tail -F is offset-based: an in-place rewrite whose new52+# Current line only. Truncate in place (same inode, same path) so a reader
50-# content is the SAME BYTE LENGTH as the old (icon flip, position tick) is53+# that re-reads the file every interval gets the new content and never sees
51-# invisible to it — the bar goes stale until some longer line happens by.54+# a pile of old lines. Empty state = empty file.
52-# Appending keeps the inode put and delivers every state change.
53 write_output() {55 write_output() {
54- printf '%s\n' "$1" >> "$OUTPUT_FILE"56+ if [[ -z "$1" ]]; then
57+ : > "$OUTPUT_FILE"
58+ else
59+ printf '%s\n' "$1" > "$OUTPUT_FILE"
60+ fi
55 }61 }
56 62
57 last_emit="__init__"63 last_emit="__init__"
@@ -81,12 +87,12 @@ pango_escape() {
81 printf '%s' "$s"87 printf '%s' "$s"
82 }88 }
83 89
84-# File must exist so `tail -F` can attach; do not wipe a live line.90+# File must exist for readers. Carry over at most the current line — any
85-[[ -e "$OUTPUT_FILE" ]] || : > "$OUTPUT_FILE"91+# accumulated log from an older append-mode build is dropped here.
86-92+if [[ -s "$OUTPUT_FILE" ]]; then
87-# Append-mode log grows with every emitted line; keep only the newest once large.93+ printf '%s\n' "$(tail -n 1 "$OUTPUT_FILE")" > "$OUTPUT_FILE"
88-if [[ -f "$OUTPUT_FILE" ]] && (( $(stat -c %s "$OUTPUT_FILE" 2>/dev/null || echo 0) > 1048576 )); then94+else
89- tail -n 1 "$OUTPUT_FILE" > "$OUTPUT_FILE.trim" && mv -f "$OUTPUT_FILE.trim" "$OUTPUT_FILE"95+ : > "$OUTPUT_FILE"
90 fi96 fi
91 97
92 while true; do98 while true; do
.config/waybar/config-hyprlandmodified+2 -1
@@ -79,7 +79,8 @@
79 79
80 "custom/music": {80 "custom/music": {
81 "format": "{}",81 "format": "{}",
82- "exec": "tail -n 1 -F /tmp/song_detail_last 2>/dev/null",82+ "exec": "cat /tmp/song_detail_last 2>/dev/null",
83+ "interval": 1,
83 "on-click": "bash ~/.config/scripts/shared/playerctl-active.sh play-pause",84 "on-click": "bash ~/.config/scripts/shared/playerctl-active.sh play-pause",
84 "on-click-right": "bash ~/.config/scripts/shared/show_cover.sh",85 "on-click-right": "bash ~/.config/scripts/shared/show_cover.sh",
85 "on-scroll-up": "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+",86 "on-scroll-up": "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+",
.config/waybar/config-nirimodified+2 -1
@@ -79,7 +79,8 @@
79 79
80 "custom/music": {80 "custom/music": {
81 "format": "{}",81 "format": "{}",
82- "exec": "tail -n 1 -F /tmp/song_detail_last 2>/dev/null",82+ "exec": "cat /tmp/song_detail_last 2>/dev/null",
83+ "interval": 1,
83 "on-click": "bash ~/.config/scripts/shared/playerctl-active.sh play-pause",84 "on-click": "bash ~/.config/scripts/shared/playerctl-active.sh play-pause",
84 "on-click-right": "bash ~/.config/scripts/shared/show_cover.sh",85 "on-click-right": "bash ~/.config/scripts/shared/show_cover.sh",
85 "on-scroll-up": "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+",86 "on-scroll-up": "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+",