From 58c96704c720e3796e0d12aa3008d33adac2560f Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Sun, 7 Jul 2024 19:15:04 -0400 Subject: [PATCH] fix and improvements --- brc | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/brc b/brc index 48cb5c4..4e0a26a 100644 --- a/brc +++ b/brc @@ -1316,6 +1316,15 @@ ediff() { emacs --eval "(ediff-files \"$1\" \"$2\")" } +# etail + grep. +etailg() { + _bntmp() { + ngset + tailf /var/log/exim4/mainlog /var/log/exim4/*main /var/log/exim4/paniclog /var/log/exim4/*panic -n 200 | grp "$@" + ngreset + } + bn _bntmp "$@" +} # mail related # shellcheck disable=SC2120 # we expect to pass arguments in use outside this file etail() { @@ -1691,6 +1700,33 @@ gdkill() { pk1 emacs --daemon } +# execute, grep & background with bn. usage: +# +# CMD GREP ARGS +# CMD CMD_ARGS - GREP ARGS +_grx() { + local arg + local -a cmd grep_args + cmd=("$1") + shift + for arg; do + if [[ $arg == "-" ]]; then + cmd+=("${grep_args[@]}") + grep_args=() + else + grep_args+=("$arg") + fi + done + "${cmd[@]}" | grp "${grep_args[@]}" +} +grx() { + bn _grx "$@" +} + +# grep to pipe in interactive shell +grp() { + gr --color=always --line-buffered "$@" || return $? +} gr() { grep -iIP --color=auto "$@" || return $? } @@ -1947,7 +1983,7 @@ 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 "$@"; } + _bntmp() { SYSTEMD_COLORS=true journalctl -n1000 -f | grp "$@"; } bn _bntmp "$@" } jru() { @@ -1958,7 +1994,7 @@ jrug() { local unit unit="$1" shift - SYSTEMD_COLORS=true journalctl -n1000 -f -u "$unit" | gr --line-buffered "$@" + SYSTEMD_COLORS=true journalctl -n1000 -f -u "$unit" | grp "$@" } bn _bntmp "$@" } @@ -2360,7 +2396,7 @@ 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). +# first, and use grep --line-buffered --color=always (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 @@ -2369,7 +2405,8 @@ _bn() { local line lwlc i "$@" |& while read -r line; do # lwlc = line wrapped line count. - lwlc=$(( ${#line} / COLUMNS + 1 )) + # https://stackoverflow.com/questions/17998978/removing-colors-from-output + lwlc=$(( $(printf %s "$line" | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g" | wc -c ||:) / COLUMNS + 1 )) # from man terminfo # tput sc = \e7 = save cursor # tput rc = \e8 = restore cursor @@ -2968,7 +3005,7 @@ slr() { # ssh with multiplexing. ssm() { sl -oControlPath=/tmp/ssh_mux_%u_%h_%p_%r "$@" - } +} # ssh solo, without multiplexing. # currently the default, but I might switch back. sss() { ssh -oControlPath=none "$@" -- 2.30.2