From 330f501489946f4c682d247520a64180b384ac36 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Fri, 19 Dec 2025 00:56:46 -0500 Subject: [PATCH] fix profanity notifications --- distro-end | 1 - filesystem/usr/local/bin/prof | 2 +- filesystem/usr/local/bin/prof-notify | 9 ++- filesystem/usr/local/bin/prof-remote | 2 +- filesystem/usr/local/bin/prof-tail | 68 +++++++++++++------ .../.config/systemd/user/prof-tail.service | 17 ----- 6 files changed, 57 insertions(+), 42 deletions(-) delete mode 100644 subdir_files/.config/systemd/user/prof-tail.service diff --git a/distro-end b/distro-end index 496c7c5..34acd4b 100755 --- a/distro-end +++ b/distro-end @@ -1180,7 +1180,6 @@ case $HOSTNAME in ln -sfT /d/p/profanity-config ~/.config/profanity if [[ $HOSTNAME == "$HOST2" || ! -e /p/profanity-here ]]; then systemctl --user --now enable profanity - systemctl --user --now enable prof-tail fi ;; *) diff --git a/filesystem/usr/local/bin/prof b/filesystem/usr/local/bin/prof index 793d09a..b7ddf7f 100755 --- a/filesystem/usr/local/bin/prof +++ b/filesystem/usr/local/bin/prof @@ -41,7 +41,7 @@ if $dossh; then export IANK_BASHRC_RUN="prof-remote $remote" konsole --profile profanity else - prof-tail | prof-notify & + prof-tail & konsole --profile profanity -e tmux -L profanity a fi diff --git a/filesystem/usr/local/bin/prof-notify b/filesystem/usr/local/bin/prof-notify index ebcc28e..ef66031 100755 --- a/filesystem/usr/local/bin/prof-notify +++ b/filesystem/usr/local/bin/prof-notify @@ -26,10 +26,13 @@ set -e; . /usr/local/lib/bash-bear; set +e pkill -fxA '/bin/bash /usr/local/bin/prof-notify' ||: -while read -r line; do +while true; do + read -r line ||: + #echo "prof-notify debug line: $line" + # check that the profanity window is not focused - if ! i3-check-profanity &>/dev/null; then + if [[ $line ]] && ! i3-check-profanity &>/dev/null; then # the profanity tag makes it so new notification replaces old. - dunstify -h string:x-dunst-stack-tag:profanity $line + dunstify -h string:x-dunst-stack-tag:profanity -- "$line" fi done diff --git a/filesystem/usr/local/bin/prof-remote b/filesystem/usr/local/bin/prof-remote index a34be7c..a413d56 100755 --- a/filesystem/usr/local/bin/prof-remote +++ b/filesystem/usr/local/bin/prof-remote @@ -33,7 +33,7 @@ while true; do fi # -n or else it competes with the other ssh for reading stdin. # -l iank is just a safety measure against misconfig/temporary config in .ssh/config. - ssh -l iank -n $remote tail -n0 -qF /home/iank/.local/share/profanity/prof-tail.log | prof-notify & + ssh -l iank -n $remote -- prof-tail -r | prof-notify & ssh -l iank -t $remote tmux -L profanity a ||: builtin kill %% &> /dev/null ||: if (( EPOCHSECONDS > start + 600 )); then diff --git a/filesystem/usr/local/bin/prof-tail b/filesystem/usr/local/bin/prof-tail index c84d77a..0bf0dd5 100755 --- a/filesystem/usr/local/bin/prof-tail +++ b/filesystem/usr/local/bin/prof-tail @@ -20,9 +20,23 @@ # See the License for the specific language governing permissions and # limitations under the License. - set -e; . /usr/local/lib/bash-bear; set +e +remote=false +if [[ $1 == -r ]]; then + remote=true + shift +fi + +debug=false +if [[ $1 == -d ]]; then + debug=true + shift +fi + + +pkill -fA '^/bin/bash /usr/local/bin/prof-tail' ||: + # kill 0 doesn't seem to be documented in man bash, but it kills the # background processes. @@ -51,6 +65,35 @@ xmpp_users=( jtuttle ) +tail-cmd() { + # example room chat log: + # + # 2025-11-25T07:56:12.307132-05 - zoe: morning here for an hour + # + # example pm chat log: + # + # 2025-11-02T16:29:27.100202-05 - me: ok. good luck + # 2025-11-02T17:42:02.547790-05 - zoe@fsf.org: oh damn + + # note: man timeout says 124 is when timeout times out. + # for debugging, add test2 to the room list and use jtuttle with pidgin. + timeout $secs_till_midnight tail -n0 -qF \ + $logdir/rooms/{sys-private,office,operations}_at_conference.fsf.org/$log_today ${user_logs[@]} 2>/dev/null \ + | sed -urn "/$pre iank: /d;s/$pre ([^@ ]+: .*\biank\b.*)/\1/p;s/$pre ([^@:]+)@.*/pm: \1/p" || [[ ${PIPESTATUS[0]} == 124 ]] + +} + +notify-cmd() { + local line="$1" + if $debug; then + echo "prof-notify debug line: $line" + fi + + # check that the profanity window is not focused + if [[ $line ]] && ! i3-check-profanity &>/dev/null; then + dunstify -h string:x-dunst-stack-tag:profanity -- "$line" + fi +} pre="^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}-[0-9]{2} -" @@ -64,24 +107,11 @@ while true; do user_logs+=($logdir/${u}_at_fsf.org/$log_today) done - # example room chat log: - # - # 2025-11-25T07:56:12.307132-05 - zoe: morning here for an hour - # - # example pm chat log: - # - # 2025-11-02T16:29:27.100202-05 - me: ok. good luck - # 2025-11-02T17:42:02.547790-05 - zoe@fsf.org: oh damn - - # psuedocode simplified strategy: - # tail room_logs | grep -v '^pre iank:' | grep iank | tail - pm_logs | grep -v "^$pre me:" - # shellcheck disable=SC2046 # intentional - timeout --foreground $secs_till_midnight tail -n0 -qF \ - $logdir/rooms/*/$log_today 2>/dev/null \ - | sed -rn "/$pre iank: /d;s/$pre /room: /;/\biank\b/p" \ - | tail -n0 -qf --retry -- - ${user_logs[@]} \ - | sed -rn "s/$pre ([^@:]+)@.*/pm: \1/p;/^room: /p" || [[ ${PIPESTATUS[0]} == 124 ]] - # note: man timeout says 124 is when timeout times out. + if $remote; then + tail-cmd + else + tail-cmd | while :; do read -r l; notify-cmd "$l"; done + fi sleep 2 done diff --git a/subdir_files/.config/systemd/user/prof-tail.service b/subdir_files/.config/systemd/user/prof-tail.service deleted file mode 100644 index c77c8ad..0000000 --- a/subdir_files/.config/systemd/user/prof-tail.service +++ /dev/null @@ -1,17 +0,0 @@ -[Unit] -Description=profanity log tail for notifications -After=gpg-agent.service - -# This service exists because killing leftover prof-tail would still -# leave around its subprocesses. I think its cuz the signal doesn't -# propogate, and it would if i killed the process group, but i don't -# know how, so just do this and have 1 process which tails a single -# file. -# -# -[Service] -ExecStart=/usr/local/bin/prof-tail -StandardOutput=truncate:/home/iank/.local/share/profanity/prof-tail.log - -[Install] -WantedBy=default.target -- 2.30.2