From: Ian Kelling Date: Mon, 11 Dec 2023 11:37:22 +0000 (-0500) Subject: various fixes X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=7f6a974222bd0f3936b61a8430d3e28a13307632;p=distro-setup various fixes --- diff --git a/brc b/brc index 4274d6e..aaaf87c 100644 --- a/brc +++ b/brc @@ -2181,7 +2181,7 @@ skq() { skgit() { local f for f in $(i s | awk '$1 == "modified:" {print $2}'); do - if [[ $(head -n1 "$f") == '#!/bin/bash'* ]]; then + if istext "$f" && [[ $(head -n1 "$f" 2>/dev/null) == '#!/bin/bash'* ]]; then sk $f ||: fi done @@ -2788,7 +2788,7 @@ vim() { # ls count. usage: pass a directory, get the number of files. # https://unix.stackexchange.com/questions/90106/whats-the-most-resource-efficient-way-to-count-how-many-files-are-in-a-director lsc() { - # shellcheck disable=SC2790 # intentional + # shellcheck disable=SC2790 disable=SC2012 # intentional ls -Uq "$@"|wc -l } diff --git a/brc2 b/brc2 index 1a6db0c..195f3dd 100644 --- 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) diff --git a/btrfsmaint b/btrfsmaint index 4b851a1..0a36d05 100755 --- a/btrfsmaint +++ b/btrfsmaint @@ -33,6 +33,7 @@ e() { check-idle() { type -p xscreensaver-command &>/dev/null || return 0 + export XAUTHORITY=/home/iank/.Xauthority export DISPLAY=:0 locked=false if lock_info=$(xscreensaver-command -time); then diff --git a/filesystem/usr/local/bin/bitcoinon b/filesystem/usr/local/bin/bitcoinon new file mode 100755 index 0000000..d62e413 --- /dev/null +++ b/filesystem/usr/local/bin/bitcoinon @@ -0,0 +1,4 @@ +#!/bin/bash +[[ $EUID == 0 ]] || exec sudo "${BASH_SOURCE[0]}" + +systemctl start bitcoind diff --git a/myi3status b/myi3status index 9aeccca..d8c5d22 100755 --- a/myi3status +++ b/myi3status @@ -57,9 +57,11 @@ source /a/bin/errhandle/err shopt -s nullglob shopt -s dotglob +tmp_focus1=$(mktemp) +tmp_focus2=$(mktemp) + mins=0 half_hours=0 -fast_blocks=30 start=$EPOCHSECONDS domins=false @@ -137,6 +139,26 @@ main() { printf '[' + if [[ -e /dev/shm/iank-status && ! -e /tmp/quiet-status ]]; then + ps_char= + eval "$(< /dev/shm/iank-status)" + fi + + touch --date="10 minutes ago" $tmp_focus1 + touch --date="30 minutes ago" $tmp_focus2 + f=/tmp/focus-last-input + + # We output a reminder to do input to the focus app if we haven't done + # it less 10 minutes ago (but dont bother if its been more than 30 + # minutes, maybe we aren't running it anymore.) + if [[ -e $f && $tmp_focus2 -ot $f && $tmp_focus1 -nt $f ]]; then + ps_char="=======FOCUS====== $ps_char" + fi + + + printf '{ "name":"status", "color":"#ED297D", "full_text": "%s' "$ps_char" + printf '"},' + if [[ $start2 ]]; then time2=$((EPOCHSECONDS - start2)) @@ -238,7 +260,7 @@ main() { # there are 9 spark levels, 1/9 = .111.... In order to keep it in bash math, we upscale # the number and divide by 111, 3 digits is good enough accuracy. - spark_index="$(( (1000000 -($EPOCHSECONDS - $day_start)*1000000 / (16*60*60) ) % 1000 / 111 ))" + spark_index="$(( (1000000 -(EPOCHSECONDS - day_start)*1000000 / (16*60*60) ) % 1000 / 111 ))" spark=" ▁▂▃▄▅▆▇█" # note: 960 minutes, so 10 minutes is about 1% day_thousandth=$(( 1000 - (EPOCHSECONDS - day_start)*1000 / (16*60*60) )) @@ -277,3 +299,5 @@ else read -r -t 3 line ||: done fi + +rm -f $tmp_focus1 $tmp_focus2 diff --git a/prof-remote b/prof-remote index 422bb6e..787335d 100644 --- a/prof-remote +++ b/prof-remote @@ -7,6 +7,9 @@ remote=$1 fastcon=0 while true; do start=$EPOCHSECONDS + if ! ssh-add -l | grep SHA256:YEhwH5u+wkqkSl/dCq8rFebi2qz7Os3RmIWPxMg13eA &>/dev/null; then + ssh -n $remote + fi # -n or else it competes with the other ssh for reading stdin. ssh -n $remote prof-tail | prof-notify & ssh -t $remote screen -Dr -S profanity ||: diff --git a/system-status b/system-status index 28b3024..6b25454 100755 --- a/system-status +++ b/system-status @@ -443,6 +443,7 @@ if [[ $1 ]]; then exit 0 fi +loop_count=0 main-loop() { while true; do power=true @@ -450,16 +451,25 @@ main-loop() { power=false fi wait=15 - if ! $power; then - if systemctl -q is-active bitcoind; then - bitcoinoff + + if $power; then + if (( loop_count % 10 == 0 )); then + bat=$(cat /sys/class/power_supply/BAT0/capacity) + case $bat in + 100|9?) + bitcoinon & + ;; + esac fi + else + bitcoinoff wait=60 fi sleep $wait write-status mute + loop_count=$(( loop_count + 1 )) done }