From adef8d413fb931453dae2bffa9a1bb59b1b307ec Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Tue, 19 Nov 2024 03:58:27 -0500 Subject: [PATCH] minor improvements --- brc | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++--- brc2 | 24 ++++++--- distro-end | 2 + 3 files changed, 166 insertions(+), 13 deletions(-) diff --git a/brc b/brc index f8691ed..9ba1512 100644 --- a/brc +++ b/brc @@ -362,6 +362,15 @@ mysrc /a/bin/fai/fai/config/distro-install-common/bash-misc-funcs # This also looks like it could be customized more than fzf: # https://github.com/lotabout/skim +# * aliases + +alias n=continue + +# quicker function definition +alias 8='f(){' +alias 9='};' + + # * functions @@ -3660,10 +3669,6 @@ rn() { dunstify -u critical -h string:x-dunst-stack-tag:profanity "$*" _psrun=(dunstctl close-all) } -n() { - dunstify -u critical -h string:x-dunst-stack-tag:profanity n - _psrun=(dunstctl close-all) -} catnew() { local dir file _ @@ -4192,16 +4197,149 @@ mvf() { mv "${f[@]}" "$dest" } -# f execute. speculating this will come in handy. +# f execute. fe() { "$@" "${f[@]}" } +# f maybe. +# +# usage: fm COMMAND... [-] FILES... +# +# Create ${f[@]} by running COMMAND on each of FILES, if the command +# succeeds, add it to ${f[@]}; +# +# The first arg that is an existing file starts the FILES args, or an arg "-". +fm() { + local file end_arg=false in_files=false + local -a files cmd + f=() + for a; do + if [[ $a == - ]]; then + end_arg=true + break + fi + done + for a; do + if ! $in_files; then + if $end_arg; then + if [[ $a == - ]]; then + in_files=true + shift + continue + fi + elif [[ -L $a || -e $a ]]; then + in_files=true + else + cmd+=("$a") + shift + fi + fi + if $in_files; then + if "${cmd[@]}" "$a"; then + f+=("$a") + fi + fi + done +} +# example shortening: +# for f in *; do t -x $a && sk $a; done +# becomes +# fm t -x *; fe sk + + +# execute on executables +# usage: xe COMMAND... [-] FILES... +# +# Filter FILES to be executable files (remove directories). +# +# The first arg that is an existing file starts the FILES args, or an arg "-". +xe() { + local file end_arg=false in_files=false + local -a files cmd + for a; do + if [[ $a == - ]]; then + end_arg=true + break + fi + done + for a; do + if ! $in_files; then + if $end_arg; then + if [[ $a == - ]]; then + in_files=true + shift + continue + fi + elif [[ -L $a || -e $a ]]; then + in_files=true + else + cmd+=("$a") + shift + fi + fi + if $in_files; then + if [[ -f $a && -x $a ]]; then + files+=("$a") + fi + fi + done + if (( ${#files[@]} == 0 )); then + echo $0: error: no files found >&2 + return 1 + fi + "${cmd[@]}" "${files[@]}" +} + +# execute on directories +# usage: xd COMMAND... [-] FILES... +# +# Filter FILES to just directories +# +# The first arg that is an existing file starts the FILES args, or an arg "-". +xd() { + local file end_arg=false in_files=false + local -a files cmd + + for a; do + if [[ $a == - ]]; then + end_arg=true + break + fi + done + for a; do + if ! $in_files; then + if $end_arg; then + if [[ $a == - ]]; then + in_files=true + shift + continue + fi + elif [[ -L $a || -e $a ]]; then + in_files=true + else + cmd+=("$a") + shift + fi + fi + if $in_files; then + if [[ -d $a ]]; then + files+=("$a") + fi + fi + done + if (( ${#files[@]} == 0 )); then + echo $0: error: no files found >&2 + return 1 + fi + "${cmd[@]}" "${files[@]}" +} + # Save some for loop typing. Run COMMAND on each of FILES, striping any # leading paths. # -# CD_DIRECTORY is assumed if FILES are in the current directory. +# CD_DIRECTORY is assumed if FILES exist in the current directory. # # usage: [ CD_DIRECTORY ] COMMAND... FILES.. forf() { @@ -4251,6 +4389,9 @@ ep() { done } +t() { test "$@"; } + + # * stuff that makes sense to be at the end diff --git a/brc2 b/brc2 index b89604a..d3230ff 100644 --- a/brc2 +++ b/brc2 @@ -2342,6 +2342,16 @@ hsk() { done } +# timetrap. it has a single letter name which it does not deserve to take up. +tt() { + local f cmd + # get highest version if we have more than one. + for f in ~/.local/share/gem/ruby/*/bin/t; do + cmd=$f + done + $cmd "$@" + } + ## work log # # note: database location is specified in ~/.timetrap.yml, currently /p/.timetrap.db @@ -2351,20 +2361,20 @@ wlog() { for (( i=days_back; i>=0; i-- )); do day=$( date +%F -d @$((EPOCHSECONDS - 86400*i )) ) date "+%a %b %d" -d @$((EPOCHSECONDS - 86400*i )) | tr '\n' ' ' - /a/opt/timetrap/bin/t d -ftotal -s $day -e $day all -m '^w|lunch$' + tt d -ftotal -s $day -e $day all -m '^w|lunch$' done } -to() { we t out -a "$@"; } -ti() { we t in -a "$@"; } +to() { we tt out -a "$@"; } +ti() { we tt in -a "$@"; } _tl() { local in_secs to "$*" - t s lunch - t in -a "$*" + tt s lunch + tt in -a "$*" in_secs="$(date -d "${*//[_.]/ }" +%s)" - m t out -a "$(date +%F.%T -d @$(( in_secs + 60*45 )) )" - t s w + m tt out -a "$(date +%F.%T -d @$(( in_secs + 60*45 )) )" + tt s w } tl() { we _tl "$@" diff --git a/distro-end b/distro-end index 463580f..0cb9679 100755 --- a/distro-end +++ b/distro-end @@ -1899,6 +1899,8 @@ s sed -ri "s/^([[:space:]]*ui.print_\('Playing)/#\1/" /usr/share/beets/beetsplug # they are useful. So on server, just run barriers, client run barrierc SERVER_IP ### begin timetrap setup + +# note, I also have a build at /a/opt/timetrap/bin/t, but this is more recent. if mountpoint /p &>/dev/null; then mkdir -p ~/.timetrap/ ln -sf /a/opt/timetrap_formatters ~/.timetrap/formatters -- 2.30.2