From 641d0cedd75d9580701e3c9493147b8c73fbe6b8 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Sat, 1 Mar 2025 13:19:50 -0500 Subject: [PATCH] fix jdo, minor improvements --- brc | 97 +++++++++++++++---------------------------------------------- 1 file changed, 23 insertions(+), 74 deletions(-) diff --git a/brc b/brc index 4acc197..24b4cdd 100644 --- a/brc +++ b/brc @@ -724,7 +724,7 @@ jdo() { journalctl --since=now -qn2 -f -u "$unit_name" & jr_pid=$! # sleep 1 is too fast for x200. sleep 3 was too fast for a fast computer. - sleep 4 + sleep 5 $sdrun_prefix systemd-run $sdrun_args --unit "$unit_name" --wait --collect "$cmd" "$@" || ret=$? # The sleep lets the journal output its last line # before the prompt comes up. @@ -739,7 +739,7 @@ ccomp time jdo # standard date as used in logs datelog() { - date +%Y-%m-%d "$@" + date +%F "$@" } # timestamp in log appropriate format @@ -3008,7 +3008,7 @@ sk() { local quotes others ret quotes=2048,2064,2068,2086,2119,2206,2254,2231 others=2029,2032,2033,2054,2164,2317 - shellcheck -x -W 999 -e $quotes,$others "$@" || ret=$? + shellcheck -a -x -W 999 -e $quotes,$others "$@" || ret=$? if (( ret >= 1 )); then echo "A template comment to disable is now in clipboard. eg: # shellcheck disable=SC2206 # reason" cbs "# shellcheck disable=SC" @@ -4144,7 +4144,7 @@ tcpdump() { # / search, {, }: next/prev match # ctrl/alt-v scroll forward/backward within this node # l: go to previous node -info-pe() { +bash-info() { info bash 'Basic Shell Features' 'Shell Expansions' 'Shell Parameter Expansion' } @@ -4519,82 +4519,31 @@ logexec() { exec &> >(pee cat 'ts "%F %T" >>'$log_path) } -## begin debug-setx background / development notes -# -# I often end up writing little 5-10 line scripts. To log what they are doing, -# I was annoyed with the available options. #1 There is set -x, which usually ends up -# being > 50% useless lines, very anoying. #2 -# m() { printf "%s\n" "$*"; -#"$@"; } that annoyingly conflicts with command -# redirected output, and I constantly forget to add it. -# -# Better option: debug trap, where we can print $BASH_COMMAND. The main -# annoying thing about this is that $BASH_COMMAND doesn't have expanded -# variables. -# -# options to expand variables in a $BASH_COMMAND: -# -# 1. get bash to do readline's shell-expand-line. I know a hacky way -# with read, but it wasn't reliable when I tried it in a -# prompt_command. I could probably create a c program that uses readline -# to do it pretty easily -# -# 2. Use the prompt expansion features @P, but first escape the special -# prompt characters if there are any. This was the option I went -# with. It has a small flaw that I realized without calling a regex -# substitution program, my escaping is not perfect: I temporarily insert -# a long random string to identify "\\", but it is possible this string -# could exist in the command and then I would improperly replace -# it. However, my use case is simply viewing commands I intend to run -# and I don't see any reason I would intend to run a command with that -# or that even if I did, it would cause any serious problem to have it -# be incorrectly displayed. -# -# NOTE: One imperfection with both of these, is that we don't want to -# expand $() or ``, so I look for those chars and then avoid doing it. I -# think the only way to avoid this would be to modify bash itself in -# order to do shell-expand-line and then use the result, just as if you -# pressed the key for it. -# -# \\ -> \\\\ : creates problem matching eg: \e -# -# alternate: -# -# \134 -> RANDOM_LONG_STRING -# -# \\ -> \134\134 : creates problem matching \134, we need to match \134!(\134), solved by the RANDOM_LONG_STRING -# -# \a -> \134a -# -# \D{*} and \123 -> \\& -# -# RANDOM_LONG_STRING -> \\134 -# -# alternate, best: -# -# \\ -> RANDOM_LONG_STRING -# -# \a -> \\a -# -# \D{*} and \123 -> \\& -# -# RANDOM_LONG_STRING -> \\\\ -# -# # incrementally built up test cases, where the output is expected to be the same as the initial _d + + +# Run $1, with argument of */*, but only actually pass in one file per directory. # -# _d='ok\\\\jyes'; _d="${_d//'\\'/SUBfopguensOfRifejmuSUB}" _d="${_d//\\[adehHjlnrstT@AuvVwW\!\#\$[\]]/\\&}" _d="${_d//SUBfopguensOfRifejmuSUB/'\\\\'}"; e "$_d + ${_d@P}" +# example: # -# _d='ok\D{z_ds}yes'; _d="${_d//'\\'/SUBfopguensOfRifejmuSUB}" _d="${_d//\\[adehHjlnrstT@AuvVwW\!\#\$[\]]/\\&}" _d="${_d//\\D\{*\}/\\&}" _d="${_d//SUBfopguensOfRifejmuSUB/'\\\\'}"; e "$_d + ${_d@P}" +# file tree: # -# _d='ok\144ye\134s'; _d="${_d//'\\'/SUBfopguensOfRifejmuSUB}" _d="${_d//\\[adehHjlnrstT@AuvVwW\!\#\$[\]]/\\&}" _d="${_d//\\D\{*\}/\\&}" _d="${_d//\\[012][0-9][0-9]/\\&}" _d="${_d//\\3[0-6][0-9]/\\&}" _d="${_d//\\37[0-7]/\\&}" _d="${_d//SUBfopguensOfRifejmuSUB/'\\\\'}"; e "$_d + ${_d@P}" +# foo/x +# foo/y +# bar/z +# bar/a # +# so, d1 ls would do +# ls foo/x bar/z # -# random interesting script: -# x=4 -# echo "\$x ${BASH_COMMAND@P}" -# Warning: Program '/bin/bash' crashed. +# I don't know what use case I had for this. # -## end debug-setx background / development notes +d1() { + local -a args + local f i + for f in *; do for i in "$f"/*; do args+=( "$i" ); break; done; done + $1 "${args[@]}" +} + # * stuff that makes sense to be at the end -- 2.30.2