various fixes
[distro-setup] / brc2
diff --git a/brc2 b/brc2
index 1a6db0cc38d5d4978c389c9d0d1418d2a36d90db..195f3dd36d94fc90d6e862f5487c130307b2ba96 100644 (file)
--- a/brc2
+++ b/brc2
@@ -2199,6 +2199,8 @@ tl() {
   t s w
 }
 
+
+# help me focus. opens 2 windows.
 focus() {
   /p/c/proc/focus/linux-amd64/focus &
   watcharb5
@@ -2206,12 +2208,17 @@ focus() {
 }
 
 
+# Display a list of the active window title
+# i've been on with 10 second samples going back
+# 5 minutes. If I've been on one window for 10 seconds
+# or longer, then display the second count.
+#
+# Press any key to exit.
 watcharb5() {
   local char ret
-  killall arbtt-capture ||:
+  killall arbtt-capture &>/dev/null ||:
   rm -f ~/.arbtt/capture.log
   arbtt-capture --sample-rate=10 &
-  clear
   while true; do
     arb5
     ret=0
@@ -2228,30 +2235,49 @@ watcharb5() {
       killall arbtt-capture ||:
       return 0
     fi
-    clear
   done
 
 }
 
 arb5() {
-  local i l sec
-  i=0
+  local i j l sec blanks line
+  local -a arbtt_lines
   if [[ ! -e ~/.arbtt/capture.log ]]; then
     sleep 5
   fi
-  # https://stackoverflow.com/questions/56486272/how-to-concat-multiple-fields-to-same-line-with-jq
-  arbtt-dump -l 30 -t json | jq -r '.[] | [ ( .inactive  / 1000 | floor ) , ( .windows[] | select (.active == true) |.title) ] | @tsv' \
-    | tac | while read -r sec l; do
-    if (( i % 6 == 0 && i >= 2 )); then
-      echo "## $(( i / 6 + 1 )) ##"
-    fi
-    if (( sec > 10 )); then
-      printf "%3d %s\n" $sec "$l"
-    else
-      printf "    %s\n" "$l"
-    fi
-    i=$(( i + 1 ))
+  blanks=$(( LINES - 34 ))
+  for (( i=0; i < blanks; i++ )); do
+    echo
   done
+
+  {
+    i=0
+    j=0
+    # https://stackoverflow.com/questions/56486272/how-to-concat-multiple-fields-to-same-line-with-jq
+    arbtt_lines=$(arbtt-dump -l 30 -t json | \
+                    jq -r '.[] | [ ( .inactive  / 1000 | floor ) , ( .windows[] | select (.active == true) |.title) ] | @tsv' | tac)
+    for line in "${arbtt_lines[@]}"; do
+      read -r sec l <<<"$line"
+      if (( j >= LINES )); then
+        break
+      fi
+      if (( i % 6 == 0 && i >= 2 )); then
+        j=$(( j + 1 ))
+        echo "## $(( i / 6 + 1 )) ##"
+      fi
+      if (( sec > 10 )); then
+        printf "%3d %s\n" $sec "$l" | sed -r "s/^(.{$COLUMNS}).*/\1/"
+      else
+        printf "    %s\n" "$l" | sed -r "s/^(.{$COLUMNS}).*/\1/"
+      fi
+      i=$(( i + 1 ))
+      j=$(( j + 1 ))
+    done
+    while (( j < 34 && j < LINES )); do
+      echo
+      j=$(( j + 1 ))
+    done
+  } | tac
 }
 
 arbttlog() {
@@ -2885,6 +2911,34 @@ myprof() {
   popd
 }
 
+
+# Tail all recent prof logs. Copying from profanity has unwanted line breaks
+# especially for links.
+profr() {
+  case $HOSTNAME in
+    kd)
+      profr-local
+      ;;
+    *)
+      ssh b8.nz profr-local
+      ;;
+  esac
+}
+
+profr-local() {
+  local d0 d1
+  local -a files
+  d0="$(date +%Y_%m_%d).log"
+  d1="$(date -d '1 day ago' +%Y_%m_%d).log"
+  ngset
+  files=(/d/p/profanity/chatlogs/iank_at_fsf.org/{*,rooms/*}/{$d0,$d1})
+  ngreset
+  if (( ${#files[@]} > 0 )); then
+    cat "${files[@]}" | sort | tail -n 40
+  fi
+}
+
+
 # Tail pms in the last day, for the case where we restart profanity and
 # didn't check for pms beforehand. Assume the most recent logs are on kd.
 # If that isn't the case, use prof-recent-local
@@ -2898,7 +2952,6 @@ prof-recent() {
       ;;
   esac
 }
-
 prof-recent-local() {
   local d dates date files f
   # consider making the day count passed by parameter. note: this works: $(date -d '2 day ago' +%Y_%m_%d)