From cb297065727f93c14682a03f5edd553c50c4b01b Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Sat, 6 Jul 2024 22:17:21 -0400 Subject: [PATCH] minor improvements --- brc | 87 ++++++++++++++++++++++++++++++++++------------ brc2 | 27 ++++++++++++-- brc3 | 23 ++++++++++++ distro-end | 1 + i3-check-profanity | 43 +++++++++++++++++++++++ prof-notify | 2 +- prof-tail | 1 + 7 files changed, 158 insertions(+), 26 deletions(-) create mode 100644 brc3 create mode 100755 i3-check-profanity diff --git a/brc b/brc index c3d7686..0f7d7e8 100644 --- a/brc +++ b/brc @@ -1341,10 +1341,28 @@ tailf() { } ta() { - bn ta "$@" + bn tailf "$@" } +tag() { + _bntmp() { + local file + file="$1" + tailf "$file" | gr --line-buffered "$@" + } + bn _bntmp "$@" +} + ccomp tail etail etail2 ta +_cron-test() { + tailf /var/log/syslog | gr --line-buffered cron +} + +cron-test() { + echo "cron will check for new files in about $(( 60 - $(date +%S) + 2 )) seconds" + bn _cron-test +} + # ran into this online, trying it out detach() { ( "$@" &>/dev/null & disown ) @@ -1928,10 +1946,21 @@ pst() { jrt() { journalctl -e -n100000 -o short-full "$@"; } jr() { journalctl -e -n100000 "$@" ; } jrf() { SYSTEMD_COLORS=true bn journalctl -n1000 -f "$@" ; } +jrfg() { + _bntmp() { SYSTEMD_COLORS=true journalctl -n1000 -f | gr --line-buffered "$@"; } + bn _bntmp "$@" +} jru() { - # the invocation id is "assigned each time the unit changes from an inactive - # state into an activating or active state" man systemd.exec - journalctl -e --no-tail -u exim4 _SYSTEMD_INVOCATION_ID="$(systemctl show -p InvocationID --value $1)" + SYSTEMD_COLORS=true bn journalctl -n1000 -f -u "$@" ; +} +jrug() { + _bntmp() { + local unit + unit="$1" + shift + SYSTEMD_COLORS=true journalctl -n1000 -f -u "$unit" | gr --line-buffered "$@" + } + bn _bntmp "$@" } ccomp journalctl jr jrf jru @@ -2330,29 +2359,36 @@ weoff() { # # The name bn is not special. # +# Note: if you want to tail -f | grep, wrap it in a function +# first, and use grep --line-buffered (because we are piping to a pipe). +# # Note: colorization will need to be turned on since it captures # output to a pipe, eg: SYSTEMD_COLORS=true bn journalctl -f -bn() { +# +_bn() { local line lwlc i - { - "$@" |& while read -r line; do - # lwlc = line wrapped line count. - lwlc=$(( ${#line} / COLUMNS + 1 )) - # from man terminfo - # tput sc = \e7 = save cursor - # tput rc = \e8 = restore cursor - # tput hpa 0 = \e[1G = move cursor to column 0 - # tput il X = \e[XL = insert X lines - # tput ind = \eD = (according to - # https://superuser.com/questions/1106674/how-to-add-blank-lines-above-the-bottom-in-terminal - # But I can't verify because cannot be captured into a var from tput.) - #\e[XA = up X lines - for (( i=0; i < lwlc; i++ )); do - echo -ne "\eD" - done - echo -ne "\e7\e[${lwlc}A\e[1G\e[${lwlc}L$line\e8" + "$@" |& while read -r line; do + # lwlc = line wrapped line count. + lwlc=$(( ${#line} / COLUMNS + 1 )) + # from man terminfo + # tput sc = \e7 = save cursor + # tput rc = \e8 = restore cursor + # tput hpa 0 = \e[1G = move cursor to column 0 + # tput il X = \e[XL = insert X lines + # tput ind = \eD = (according to + # https://superuser.com/questions/1106674/how-to-add-blank-lines-above-the-bottom-in-terminal + # But I can't verify because cannot be captured into a var from tput.) + #\e[XA = up X lines + for (( i=0; i < lwlc; i++ )); do + echo -ne "\eD" done - } & + echo -ne "\e7\e[${lwlc}A\e[1G\e[${lwlc}L$line\e8" + done +} +bn() { + # We wrap a function rather than a long {} so that it looks nicer in + # job control output. + _bn "$@" & } # shellcheck disable=SC2120 @@ -3690,6 +3726,11 @@ fsplit() { done } + +brc3() { + source /a/c/brc3 +} + # * stuff that makes sense to be at the end diff --git a/brc2 b/brc2 index eab5d4a..6b2b5a3 100644 --- a/brc2 +++ b/brc2 @@ -4481,7 +4481,7 @@ rem() { break fi done - paths="/p/c /b/" + paths="/b/" find $paths -not \( -name .svn -prune -o -name .git -prune \ -o -name .hg -prune -o -name .editor-backups -prune \ -o -name .undo-tree-history -prune \) 2>/dev/null | grep -iP --color=auto -- "$*" ||: @@ -5023,7 +5023,30 @@ ffsencode() { localai() { schroot -c bookworm - } +} + +spdx() { + local out i input pw + out=$(gpg -q -d ~/.spd/spd/spd_data.gpg 2>/dev/null | gr "$@") + if [[ $out == *$'\n'* ]]; then + i=0 + while read -r line; do + printf "$i %s\n" "$line" | awk -F'\t' '{print $1,$2}' + i=$(( i + 1 )) + done <<<"$out" + read -r input + i=0 + while read -r line; do + if [[ $input == "$i" ]]; then + out="$line" + break + fi + i=$(( i + 1 )) + done <<<"$out" + fi + pw=$(printf "$i %s\n" "$out" | awk -F'\t' '{print $3}') + ( { printf "%s" "$pw" | xclip -selection clipboard && sleep 15 && echo " " | xclip -selection clipboard; } & ) +} export BASEFILE_DIR=/a/bin/fai-basefiles diff --git a/brc3 b/brc3 new file mode 100644 index 0000000..cd54f81 --- /dev/null +++ b/brc3 @@ -0,0 +1,23 @@ +#!/bin/bash + +## command where their main reason to exist is for documentation purposes, +# and I have no desire to always load them into my shell. + +# $1 = snapshot +btrfs-snapshot-rw() { + # -ts = type snapshot + # -f = force, required to overcome this error: + # + # ERROR: cannot flip ro->rw with received_uuid set, use force option + # -f if you really want unset the read-only status. The value of + # received_uuid is used for incremental send, consider making a + # snapshot instead. Read more at btrfs-subvolume(8) and Subvolume + # flags. + # + btrfs property set -f -ts "$1" ro false +} + +# $1 = snapshot +btrfs-snapshot-ro() { + btrfs property set -f -ts "$1" ro true +} diff --git a/distro-end b/distro-end index 742e4b6..d75553a 100755 --- a/distro-end +++ b/distro-end @@ -1252,6 +1252,7 @@ fi sudo rm -fv /etc/systemd/system/profanity.service case $HOSTNAME in kd) + # i dunno why i put it here ln -sfT /d/p/profanity ~/.local/share/profanity ln -sfT /d/p/profanity-config ~/.config/profanity source /a/bin/bash_unpublished/source-state diff --git a/i3-check-profanity b/i3-check-profanity new file mode 100755 index 0000000..5337566 --- /dev/null +++ b/i3-check-profanity @@ -0,0 +1,43 @@ +#!/usr/bin/python3 +# I, Ian Kelling, follow the GNU license recommendations at +# https://www.gnu.org/licenses/license-recommendations.en.html. They +# recommend that small programs, < 300 lines, be licensed under the +# Apache License 2.0. This file contains or is part of one or more small +# programs. If a small program grows beyond 300 lines, I plan to change +# to a recommended GPL license. + +# Copyright 2024 Ian Kelling + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import sys +from pprint import pprint +from i3ipc import Connection, Event + + +def main(): + i3 = Connection() + win = i3.get_tree().find_focused() + if not win: + exit(1) + + if not win.name == "profanity — Konsole": + exit(1) + # debug + #pprint(win.name) + #pprint(vars(win)) + + +if __name__ == "__main__": + main() diff --git a/prof-notify b/prof-notify index a378a83..3315241 100644 --- a/prof-notify +++ b/prof-notify @@ -24,7 +24,7 @@ set -e; . /usr/local/lib/bash-bear; set +e while read -r line; do # check that the profanity window is not focused - if ! i3-msg -t get_tree | jq -e '.nodes[].nodes[].nodes[].nodes[] | select(.focused==true and .name=="profanity — Konsole") |.name' &>/dev/null; then + if ! /a/c/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 fi diff --git a/prof-tail b/prof-tail index aa022bc..40d373c 100644 --- a/prof-tail +++ b/prof-tail @@ -47,6 +47,7 @@ xmpp_users=( ruben zoe jtuttle + ekokao ) # start emacs daemon for profanity if it doesnt exist. -- 2.30.2