From f5fe5af7aec9c23412c9c349e21c42f6c2208582 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Tue, 4 Jul 2023 20:11:53 -0400 Subject: [PATCH] bash: bunch of improvements --- brc | 83 +++++++++++++++++++++++++++++++--------- brc2 | 121 +++++++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 167 insertions(+), 37 deletions(-) diff --git a/brc b/brc index 97f22e1..8483735 100644 --- a/brc +++ b/brc @@ -664,6 +664,14 @@ khcopy() { ssh-copy-id $1 } +# ya, hacky hardcoded hostnames in 2023. we could do better +hssh-update() { + for host in kd x3.office.fsf.org syw; do + e $host + scp /b/fai/fai/config/files/usr/local/bin/hssh/IANK root@$host:/usr/local/bin/hssh + done +} + a() { local x x=$(readlink -nf "${1:-$PWD}") @@ -687,24 +695,46 @@ hexipv4() { } vp9() { - local f out outdir in + local f out outdir in fname origdir skip1 + origdir="$PWD" outdir=vp9 - case $1 in - --out) - outdir=$2 - shift 2 - ;; - esac + skip1=false + while [[ $1 == -* ]]; do + case $1 in + # if we got interrupted after 1st phase + -2) + skip1=true + shift + ;; + --out) + outdir=$2 + shift 2 + ;; + esac + done m mkdir -p $outdir + # first pass only uses about 1 cpu, so run in parallel for f; do - out=$PWD/$outdir/$f - in=$PWD/$f - m cd $(mktemp -d) - pwd - m ffmpeg -threads 0 -i $in -g 192 -vcodec libvpx-vp9 -vf scale=-1:720 -max_muxing_queue_size 9999 -b:v 750K -pass 1 -an -f null /dev/null - m ffmpeg -y -threads 0 -i $in -g 192 -vcodec libvpx-vp9 -vf scale=-1:720 -max_muxing_queue_size 9999 -b:v 750K -pass 2 -c:a libvorbis -qscale:a 5 $out - cd - + { + fname="${f##*/f}" + if [[ $f == /* ]]; then + in="$f" + else + in=$origdir/$f + fi + out="$origdir/$outdir/$fname" + mkdir -p /tmp/vp9/$fname + cd /tmp/vp9/$fname + if ! $skip1 && [[ ! -s ffmpeg2pass-0.log ]]; then + # -nostdin or else wait causes ffmpeg to go into stopped state. dunno why, random stackoverflow answer. + m ffmpeg -nostdin -hide_banner -loglevel error -i $in -g 192 -vcodec libvpx-vp9 -vf scale=-1:720 -max_muxing_queue_size 9999 -b:v 750K -pass 1 -an -f null /dev/null + fi + if [[ -e $out ]]; then rm -f $out; fi + m ffmpeg -nostdin -hide_banner -loglevel error -y -i $in -g 192 -vcodec libvpx-vp9 -tile-rows 2 -vf scale=-1:720 -max_muxing_queue_size 9999 -b:v 750K -pass 2 -c:a libvorbis -qscale:a 5 $out + } & done + wait -f + cd "$origdir" } utcl() { # utc 24 hour time to local hour 24 hour time @@ -1179,6 +1209,7 @@ ffremux() { # absolute path of file/dir without resolving symlinks. # +# Most of the time, I want this where I would normally use readlink. # This is what realpath -s does in most cases, but sometimes it # actually resolves symlinks, at least when they are in /. # @@ -1381,6 +1412,16 @@ ccomp grep gr grr rg() { grr "$@"; } ccomp grep rg +# recursive everything. search for files/dirs and lines. rs = easy chars to press +re() { + local query + query="$1" + find "$@" -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 "$query" + grr -m 5 "$@" +} + hr() { # horizontal row. used to break up output printf "$(tput setaf 5 2>/dev/null ||:)█$(tput sgr0 2>/dev/null||:)%.0s" $(eval echo "{1..${COLUMNS:-60}}") echo @@ -1473,9 +1514,17 @@ ipp() { git push } - ifn() { - # insensitive find + local glob + glob="$1" + shift + find -L "$@" -not \( -name .svn -prune -o -name .git -prune \ + -o -name .hg -prune -o -name .editor-backups -prune \ + -o -name .undo-tree-history -prune \) -iname "*$glob*" 2>/dev/null +} + +ifh() { + # insensitive find here. args are combined into the search string. # -L = follow symlinks find -L . -not \( -name .svn -prune -o -name .git -prune \ -o -name .hg -prune -o -name .editor-backups -prune \ @@ -1782,7 +1831,7 @@ r() { # scp is insecure and deprecated. scp() { - rsync --inplace "$@" + rsync -Pt --inplace "$@" } ccomp rsync scp diff --git a/brc2 b/brc2 index 0211a64..b6a4bd3 100644 --- a/brc2 +++ b/brc2 @@ -393,15 +393,15 @@ astudio() { # Convert brains file path to url and vice versa # usage: brains [URL_OR_PATH] brains() { - _iki-convert /f/brains brains.fsf.org "$@" + _iki-convert '(/a)?/f/brains' brains.fsf.org "$@" } glue() { - _iki-convert /f/gluestick gluestick.office.fsf.org "$@" + _iki-convert '(/a)?/f/gluestick' gluestick.office.fsf.org "$@" } # usage: $0 REPO_PATH [URL_OR_PATH] _iki-convert() { - local url path input err repo_dir domain filename dir path + local url path input err repo_dir domain filename dir path url_dir local initial_oldpwd initial_pwd repo_dir="$1" domain="$2" @@ -425,7 +425,8 @@ _iki-convert() { ;; *) path=$(fp "$input") - url="http*://$domain/wiki/${path#$repo_dir/}" + url_dir=$(echo "$path" | sed -r "s,^$repo_dir/,,") + url="https://$domain/wiki/$url_dir" url="${url%.mdwn}/" j echo "$url" ;; @@ -554,6 +555,15 @@ EOF # beet playlist. use beetag with a playlist name bpl() { local playlist playlist_regex + case $1 in + -h|--help) + for playlist in "${!bpla[@]}"; do + printf "%s\n" "$playlist" + done + return 0 + ;; + esac + playlist="${*: -1}" playlist_regex='[a-z0-9_]' if [[ ! $playlist =~ $playlist_regex ]]; then @@ -772,6 +782,10 @@ beetag() { # shellcheck disable=SC2016 # obvious reason tmpstr=$(beet ls -f "$fmt" "$@" | { if $random; then sort -R --random-source=$pl_seed_path; else cat; fi; } ) mapfile -t initial_ls <<<"$tmpstr" + if [[ ! ${initial_ls[0]} ]]; then + echo "beetag: error: no result from beet ls $*" + return 1 + fi id_count=${#initial_ls[@]} for line in "${initial_ls[@]}"; do path="${line#*PijokVipiotOzeph }" @@ -2067,7 +2081,7 @@ rename-test() { feh() { # F = fullscren, z = random, Z = auto zoom - command feh -FzZ "$@" + command feh --auto-rotate -FzZ "$@" } @@ -2180,7 +2194,7 @@ arb5() { 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 )) == + echo "## $(( i / 6 + 1 )) ##" fi if (( sec > 10 )); then printf "%3d %s\n" $sec "$l" @@ -2201,19 +2215,22 @@ idea() { } ilogs-local() { - cd /var/lib/znc/moddata/log/iank/freenode/ - hr - for x in "#$1/"*; do - base=${x##*/} - files=() - for f in $@; do - tmp=\#$f/$base - if [[ -e $tmp ]]; then - files+=(\#$f/$base) - fi - done - sed \"s/^./${base%log}/\" ${files[@]}|sort -n + d=/var/lib/znc/moddata/log/iank/ + for n in freenode libera; do + cd $d/$n hr + for x in "#$1/"*; do + base=${x##*/} + files=() + for f in $@; do + tmp=\#$f/$base + if [[ -e $tmp ]]; then + files+=(\#$f/$base) + fi + done + sed \"s/^./${base%log}/\" ${files[@]}|sort -n + hr + done done } ilogs() { @@ -2226,7 +2243,11 @@ ilog-local() { chan="$1" d=/var/lib/znc/moddata/log/iank/ for n in freenode libera; do - cd $d$n/"$chan" && hr + if [[ ! -d $d$n/"$chan" ]]; then + continue + fi + cd $d$n/"$chan" + hr for x in *; do echo $x; sed "s/^./${x%log}/" $x; hr; done @@ -3475,6 +3496,60 @@ rgm() { rg "$@" /p/w.org /a/t.org /a/work.org /b } +# re all my files more expansively +rem() { + local paths + paths="/p/c /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 "$*" + rgv -m 5 "$*" $paths ||: + } + +# setup: +# pip3 install linode-cli +# linode-cli +livp9() { + local input ip id tmp + input=$1 + if [[ $2 ]]; then + id=$2 + ip=$3 + else + tmp=$(mktemp) + echo $tmp + linode-cli --json --pretty linodes create --root_pass loxHuceygomGisun | tee $tmp + read -r ip id <<<"$(tail -n+2 $tmp | jq -r '.[0].ipv4[0] , .[0].id')" + for string in $ip $id; do + case $string in + [0-9]*) : ;; + *) + echo "livp9: bad value ip=$ip id=$id input=$input" + return 1 + ;; + esac + done + rm $tmp + + while true; do + if timeout 4 ssh $ip :; then + break + fi + sleep 3 + done + fi + ssh $ip </dev/null; then # --no-messages because of annoying errors on broken symlinks # -z = search .gz etc files - # -. = search dotfilesq + # -. = search dotfiles rg() { command rg -. -z --no-messages -L -i -M 900 --no-ignore-parent --no-ignore-vcs -g '!.git' -g '!auto-save-list' -g '!.savehist' "$@" || return $?; } #fails if not exist. ignore complete -r rg 2>/dev/null ||: @@ -3591,6 +3666,12 @@ else alias rg=grr fi +# rg with respecting vcs ignore files +rgv() { + ret=0 + command rg -. -z --no-messages -L -i -M 900 -g '!auto-save-list' -g '!.savehist' "$@" || ret=$? + return $ret +} # taken from default changes to bashrc and bash_profile -- 2.30.2