cleanup profanity notify processes
authorIan Kelling <ian@iankelling.org>
Wed, 3 Dec 2025 21:20:37 +0000 (16:20 -0500)
committerIan Kelling <ian@iankelling.org>
Wed, 3 Dec 2025 21:20:46 +0000 (16:20 -0500)
distro-end
filesystem/usr/local/bin/i3-chat
filesystem/usr/local/bin/prof
filesystem/usr/local/bin/prof-irc
filesystem/usr/local/bin/prof-notify
filesystem/usr/local/bin/prof-remote
filesystem/usr/local/bin/prof-tail
filesystem/usr/local/bin/switch-mail-host
subdir_files/.config/systemd/user/prof-tail.service [new file with mode: 0644]
subdir_files/.config/systemd/user/profanity.service

index 13692b6582661341a80cfb50e80b4544d6701b7c..c66ce7e3c5bc58d20ec591e9f5975bf67df321a7 100755 (executable)
@@ -1177,6 +1177,7 @@ 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
     ;;
   *)
index 563a4f7517526c16bd3a8bcf337443581a019144..4ed13925be046aca2291af02982699f1aee54a6a 100755 (executable)
@@ -24,6 +24,37 @@ i3-msg "workspace 4"
 if ! pgrep "^prof$" >/dev/null; then
   prof &
 fi
-if ! pgrep -f '^emacs -f my-znc-all$' >/dev/null; then
-   irc &
+# start emacs daemon for profanity if it doesnt exist.
+cmd="emacsclient -s profanity -nc"
+if ! pgrep -fx "$cmd" &>/dev/null; then
+  $cmd &>/dev/null
 fi
+
+
+
+# tree of profanity related processes:
+
+# i3-chat (ctrl+y)
+#  prof
+#   export IANK_BASHRC_RUN="prof-remote $remote"
+#   konsole --profile profanity
+#     prof-remote $remote
+#       ssh -n $remote tail -n0 -qF \
+#         /home/iank/.local/share/profanity/prof-tail.log | prof-notify &
+#       ssh -t $remote tmux -L profanity a ||:
+
+
+# distro_end, on $d_host
+#  systemctl --user enable --now profanity.service
+#   /b/ds/subdir_files/.config/systemd/user/profanity.service
+#    /usr/bin/tmux -L profanity new-session -d profanity
+#  systemctl --user enable --now prof-tail.service
+#    note: StandardOutput=truncate:/home/iank/.local/share/profanity/prof-tail.log
+#   /usr/local/bin/prof-tail
+#
+
+# /p/profanity-config/profrc & /d/p/profanity-config:
+# compose.editor=/usr/local/bin/prof-irc (alt-c)
+#  exec emacsclient -s profanity -a "" "$@"
+#
+# ... (not finished documenting)
index 8316316e9325a33d2c6d45a9517499af9463985e..c46d82bf82af99214d370131da2d0c86fdab30b7 100755 (executable)
@@ -45,22 +45,3 @@ else
 fi
 
 
-# tree of profanity related processes:
-
-# prof
-#  export IANK_BASHRC_RUN="prof-remote $remote"
-#  konsole --profile profanity
-#    prof-remote $remote
-#      ssh -n $remote prof-tail | prof-notify &
-#        prof-tail
-#          emacs --daemon=profanity &>/dev/null
-#      ssh -t $remote tmux -L profanity a ||:
-
-
-# on $remote
-# /b/ds/subdir_files/.config/systemd/user/profanity.service
-#   /usr/bin/tmux -L profanity new-session -d profanity
-
-# /p/profanity-config/profrc & /d/p/profanity-config:
-# compose.editor=/usr/local/bin/prof-irc
-# ... (not finished documenting)
index d3ad9ba39bf501be58cbbba4e23c4aab226bfec0..b9dc2863063dd359b29ea9aaef14119b3b5e0e8e 100755 (executable)
@@ -26,7 +26,7 @@
 # note: this is NOT in the online manual list of commands, that has got to
 # be a bug.
 
-# This, along with changes to emacs init file and prof-remote allows us
+# This, along with changes to emacs init file in mymu4e.el and prof-remote allows us
 # to press alt-c in profanity to send the current text to #fsfsys.
 exec emacsclient -s profanity -a "" "$@"
 
index a748328556dac988ec66676644018b67a9fffd87..ebcc28e949a92b523583963df0dad584e77e8825 100755 (executable)
 
 set -e; . /usr/local/lib/bash-bear; set +e
 
+# -A = --ignore-ancestors (dont kill ourselves)
+pkill -fxA '/bin/bash /usr/local/bin/prof-notify' ||:
+
+
 while read -r line; do
   # check that the profanity window is not focused
   if ! i3-check-profanity &>/dev/null; then
index d7363fe208b0cb5007d96c82d70cf6c87d265ff4..f6486568d9c9f87afbf2483da8dde684dc16d477 100755 (executable)
@@ -32,7 +32,7 @@ while true; do
     ssh -n $remote
   fi
   # -n or else it competes with the other ssh for reading stdin.
-  ssh -n $remote prof-tail | prof-notify &
+  ssh -n $remote tail -n0 -qF /home/iank/.local/share/profanity/prof-tail.log | prof-notify &
   ssh -t $remote tmux -L profanity a ||:
   builtin kill %% &> /dev/null ||:
   if (( EPOCHSECONDS > start + 600 )); then
index 40d373c47438799ced6ac69eed424d7436d6ba0d..9a9c02488e8bd0ca62fab43a2c16bce6dd0ec4e7 100755 (executable)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# hacky way to kill off old leftover processes
-pkill -O 1 -x 'prof-tail'
 
 set -e; . /usr/local/lib/bash-bear; set +e
 
+
 # kill 0 doesn't seem to be documented in man bash, but it kills the
 # background processes.
 # https://unix.stackexchange.com/questions/67532/what-does-kill-0-do-actually/67552
@@ -32,29 +31,27 @@ set -e; . /usr/local/lib/bash-bear; set +e
 # the connection dying or killing konsole, and this has no effect on either.
 #trap "kill 0" EXIT
 
+## former employees
+# anoukr
+# devinu
+# miriam
+# ruben
 
 xmpp_users=(
-  anoukr
+  andrew
   craigt
   dawnbp
-  devinu
+  ekokao
   gregf
   johnh
   jrasata
   ksiewicz
   michael
-  miriam
-  ruben
   zoe
   jtuttle
-  ekokao
 )
 
-# start emacs daemon for profanity if it doesnt exist.
-if ! pgrep -f '^emacs --daemon=profanity$' &>/dev/null; then
-  emacs --daemon=profanity &>/dev/null
-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} -"
 
 while true; do
   midnight=$(date -d '00:00:00 tomorrow' +%s)
@@ -62,17 +59,24 @@ while true; do
   log_today=$(date '+%Y_%m_%d').log
   logdir=/home/iank/.local/share/profanity/chatlogs/iank_at_fsf.org
 
-  # when this fails, it has PIPESTATUS: 124 0 1 0 0, which seems to end up with 1 as the overall code, which is not what
-  # i expected. todo: investigate if and why that is, and narrow the ||:
-  # shellcheck disable=SC2046 # intentional
-  timeout --foreground $secs_till_midnight tail -n0 -qF \
-          $(for u in ${xmpp_users[@]}; do echo $logdir/${u}_at_fsf.org/$log_today; done) 2>/dev/null \
-    | awk '$3 != "me:" {print $3; fflush()}'  | sed -u 's/^/pm /;s/@.*//' ||: &
+  # 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 \
-    | awk '$3 != "iank:"' | grep -i '\biank\b' | awk '{print $3; fflush()}' | sed 's/^/room /;s/@.*//' ||:
+    | sed -rn "/$pre iank: /d;s/$pre /room: /;/\biank\b/p" \
+    | tail -n0 -qF -- - $(for u in ${xmpp_users[@]}; do echo $logdir/${u}_at_fsf.org/$log_today; done) 2>/dev/null \
+    | sed -rn "s/$pre ([^@:]+)@.*/pm: \1/p;/^room: /p" || [[ ${PIPESTATUS[0]} == 124 ]]
+  # note: man timeout says 124 is when timeout times out.
 
-  kill %
-  sleep 1
+  sleep 2
 done
index fb3212d83b0f62febc6447e8cb43cae1c2d94683..a4c5f63556856508f69bd9e61340d557024afadb 100755 (executable)
@@ -307,9 +307,11 @@ if ! $mail_only; then
 # But if emacs ignores the signal, let it live.
 pkill -xf 'emacs --daemon' ||:
 
-if [[ -e /p/profanity-here ]]; then
-  systemctl disable --now profanity
-fi
+# iank: todo: figure this out. the only profanity service is
+# a user service, so this is wrong. commented out cuz of that.
+#if [[ -e /p/profanity-here ]]; then
+#  systemctl disable --now profanity
+#fi
 EOF
 fi
 
diff --git a/subdir_files/.config/systemd/user/prof-tail.service b/subdir_files/.config/systemd/user/prof-tail.service
new file mode 100644 (file)
index 0000000..c77c8ad
--- /dev/null
@@ -0,0 +1,17 @@
+[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
index b7b9a058056b573061475a7814862fa6962ceccd..18383783cc60d1efa75ba2b13297798f9092e608 100644 (file)
@@ -13,7 +13,6 @@ After=gpg-agent.service
 [Service]
 # tmux requirement
 Type=forking
-
 # new-session is a tmux command which allows launching profanity.
 ExecStart=/usr/bin/tmux -L profanity new-session -d profanity