X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=brc;h=83721fc80fe6a20d9d0daee14de886149ed8b546;hb=ae96136375d4c36c4b6845bbf1975695ccc4b844;hp=6389c8763dc249881d010b671daf10894d66febe;hpb=63e3670ab59869f5f74904edbe64daa943fad15f;p=distro-setup diff --git a/brc b/brc index 6389c87..83721fc 100644 --- a/brc +++ b/brc @@ -279,6 +279,16 @@ mysrc() { mysrc /a/bin/small-misc-bash/ll-function mysrc /a/bin/distro-functions/src/package-manager-abstractions +# things to remember: +# ALT-C - cd into the selected directory +# CTRL-T - Paste the selected file path into the command line +# +# good guide to some of its basic features is the readme file +# https://github.com/junegunn/fzf + +# if [[ -s /usr/share/doc/fzf/examples/key-bindings.bash ]]; then +# source /usr/share/doc/fzf/examples/key-bindings.bash +# fi # * functions @@ -654,6 +664,21 @@ khcopy() { ssh-copy-id $1 } +# ya, hacky hardcoded hostnames in 2023. we could do better +hssh-update() { + local -a failed_hosts + for host in kd x3.office.fsf.org syw; do + e $host + if ! scp /b/fai/fai/config/files/usr/local/bin/hssh/IANK root@$host:/usr/local/bin/hssh; then + failed_hosts+=($host) + fi + done + if (( ${#failed_hosts[@]} >= 1 )); then + echo failed_hosts=${failed_hosts[*]} + return 1 + fi +} + a() { local x x=$(readlink -nf "${1:-$PWD}") @@ -677,24 +702,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 @@ -867,6 +914,8 @@ ccomp bg d z() { builtin fg "$@"; } ccomp fg z +x() { builtin kill %%; } + dc() { diff --strip-trailing-cr -w "$@" # diff content } @@ -947,13 +996,18 @@ digdiff() { diff -u /tmp/digdiff <(digsort $s2 "$@") } +# date in a format i like reading dt() { date "+%A, %B %d, %r" "$@" } dtr() { date -R "$@" } -ccomp date dt dtr +# date with all digits in a format i like +dtd() { + date +%F_%T% "$@" +} +ccomp date dt dtr dtd dus() { # du, sorted, default arg of du -sh ${@:-*} | sort -h @@ -1008,7 +1062,14 @@ etail2() { } ccomp tail etail etail2 +# ran into this online, trying it out +detach() { + ( "$@" &>/dev/null & disown ) +} +showkeys() { + ssh "$@" cat .ssh/authorized_keys{,2} +} # print exim old pids @@ -1095,6 +1156,20 @@ econfdev() { update-exim4.conf -d /tmp/edev/etc/exim4 -o /tmp/edev/e.conf } +# exim grep in +# show important information about incoming mail in the exim log +egrin() { + sed -rn '/testignore|jtuttle|eximbackup/!s/^[^ ]+ ([^ ]+) [^ ]+ [^ ]+ <= ([^ ]+).*T="(.*)" from (<[^ ]+> .*$)/\1 \4\n \3/p' <${1:-/var/log/exim4/mainlog} +} + +# 2nd line is message-id: +egrinid() { + sed -rn '/testignore|jtuttle|eximbackup/!s/^[^ ]+ ([^ ]+) [^ ]+ [^ ]+ <= ([^ ]+).* id=([^ ]+) T="(.*)" from (<[^ ]+> .*$)/\1 \5\n \3\n \4/p' <${1:-/var/log/exim4/mainlog} +} +etailin() { + tail -F /var/log/exim4/mainlog | sed -rn '/testignore|jtuttle|eximbackup/!s/^[^ ]+ ([^ ]+) [^ ]+ [^ ]+ <= ([^ ]+).*T="(.*)" from (<[^ ]+> .*$)/\1 \4\n \3/p' +} + @@ -1113,12 +1188,75 @@ faf() { # find all files. use -L to follow symlinks -o -name .undo-tree-history -prune \) -type f 2>/dev/null } -# full path without resolving symlinks +# usage ffconcat FILES_TO_CONCAT OUTPUT_FILE +ffconcat() { + local tmpf + tmpf=$(mktemp) + printf "file '%s'\n" "$1" >$tmpf + while (( $# > 1 )); do + shift + printf "file '%s'\n" "$1" >>$tmpf + done + # https://trac.ffmpeg.org/wiki/Concatenate + ffmpeg -f concat -safe 0 -i $tmpf -c copy "$1" + rm $tmpf +} +ffremux() { + local tmpf tmpd + if (( $# == 0 )); then + echo ffremux error expected args >&2 + return 1 + fi + tmpd=$(mktemp -d) + for f; do + tmpf=$tmpd/"${f##*/}" + ffmpeg -i "$f" -c:v copy -c:a copy $tmpf + cat $tmpf >"$f" + done + rm -r $tmpd +} + + + +# 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 /. +# +# Note, if run on a dir, if the final component is relative, it won't +# resolve that. Use the below fpd for that. +# +# note: we could make a variation of this which +# assigns to a variable name using eval, so that we don't have to do +# x=$(fp somepath), which might save subshell overhead and look nice, +# but I'm not going to bother. fp() { - local dir base - base="${1##*/}" - dir="${1%$base}" - printf "%s/%s\n" $(cd $dir; pwd) "$base" + local initial_oldpwd initial_pwd dir base + initial_oldpwd="$OLDPWD" + initial_pwd="$PWD" + if [[ $1 == */* ]]; then + dir="${1%/*}" + base="/${1##*/}" + # CDPATH because having it set will cause cd to possibly print output + CDPATH= cd "$dir" + printf "%s%s\n" "$PWD" "$base" + CDPATH= cd "$initial_pwd" + OLDPWD="$initial_oldpwd" + else + printf "%s/%s\n" "$PWD" "$1" + fi +} +# full path of directory without resolving symlinks +fpd() { + local initial_oldpwd initial_pwd dir + initial_oldpwd="$OLDPWD" + initial_pwd="$PWD" + dir="$1" + CDPATH= cd "$dir" + printf "%s%s\n" "$PWD" "$base" + cd "$initial_pwd" + OLDPWD="$initial_oldpwd" } @@ -1285,9 +1423,22 @@ ccomp grep gr grr rg() { grr "$@"; } ccomp grep rg -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 +# 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 "$@" +} + +# horizontal row. used to break up output +hr() { + local blocks + # 180 is long enough. + blocks=██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + printf "%s\n" "$(tput setaf 5 2>/dev/null ||:)${blocks:0:${COLUMNS:-180}}$(tput sgr0 2>/dev/null||:)" } # highlight hl() { @@ -1377,9 +1528,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 \ @@ -1515,7 +1674,7 @@ ksu() { # history search unique histrm() { history -n HISTTIMEFORMAT= history | awk -v IGNORECASE=1 '{ a=$1; sub(/^ *[^ ]+ */, "") }; /'"$*"'/' - read -p "press anything but contrl-c to delete" + read -r -p "press anything but contrl-c to delete" for entry in $(HISTTIMEFORMAT= history | awk -v IGNORECASE=1 '{ a=$1; sub(/^ *[^ ]+ */, "") }; /'"$*"'/ { print a }' | tac); do history -d $entry done @@ -1539,6 +1698,15 @@ ccomp mkdir mkc mkct() { mkc $(mktemp -d) } +# mkdir the last arg, cp the rest into it +mkcp() { + mkdir -p "${@: -1}" + cp "${@:1:$#-1}" "${@: -1}" +} +mkmv() { + mkdir -p "${@: -1}" + mv "${@:1:$#-1}" "${@: -1}" +} mkt() { # mkdir and touch file local path="$1" @@ -1677,7 +1845,7 @@ r() { # scp is insecure and deprecated. scp() { - rsync --inplace "$@" + rsync -Pt --inplace "$@" } ccomp rsync scp @@ -1784,6 +1952,11 @@ reresolv() { fi } +# add annoyingly long argument which should be the default +sedi() { + sed -i --follow-symlinks "$@" +} + rmstrips() { ssh fencepost head -n 300 /gd/gnuorg/EventAndTravelInfo/rms-current-trips.txt | less } @@ -2292,6 +2465,13 @@ pson() { fi } +# prometheus node curl +pnodecurl() { + local host + host=${1:-127.0.0.1} + s curl --cert-type PEM --cert /etc/prometheus/ssl/prometheus_cert.pem --key /etc/prometheus/ssl/prometheus_key.pem --cacert /etc/prometheus/ssl/prom_node_cert.pem --resolve prom_node:9100:$host -v https://prom_node:9100/metrics +} + tx() { # toggle set -x, and the prompt so it doesnt spam if [[ $- == *x* ]]; then set +x @@ -2468,6 +2648,7 @@ spark() _spark_echo } +pdfwc() { local f; for f; do echo "$f" $(pdfinfo "$f" | awk '/^Pages:/ {print $2}'); done } # * misc stuff @@ -2554,6 +2735,10 @@ if [[ $- == *i* ]]; then if [[ $MAIL_HOST && $MAIL_HOST != "$HOSTNAME" ]]; then ps_char="@ $ps_char" fi + jobs_char= + if [[ $(jobs -p) ]]; then + jobs_char='j\j ' + fi # We could test if sudo is active with sudo -nv # but then we get an email and log of lots of failed sudo commands. # We could turn those off, but seems better not to. @@ -2563,7 +2748,7 @@ if [[ $- == *i* ]]; then if [[ ! $HISTFILE ]]; then ps_char="NOHIST $ps_char" fi - PS1="${PS1%"${PS1#*[wW]}"} $psudo\[$ps_color\]$ps_char\[$term_nocolor\] " + PS1="${PS1%"${PS1#*[wW]}"} $jobs_char$psudo\[$ps_color\]$ps_char\[$term_nocolor\] " # set titlebar. instead, using more advanced # titelbar below @@ -2579,18 +2764,22 @@ if [[ $- == *i* ]]; then _title_escape="\033]0;" fi + # make the titlebar be the last command and the current directory. settitle () { - # this makes it so we show the current command if - # one is running, otherwise, show nothing - if [[ $1 == prompt-command ]]; then + + # These are some checks to help ensure we dont set the title at + # times that the debug trap is running other than the case we + # want. Some of them might not be needed. + if (( ${#FUNCNAME[@]} != 1 || ${#BASH_ARGC[@]} != 2 || $BASH_SUBSHELL != 0 )); then return 0 fi - if (( ${#BASH_ARGC[@]} == 1 && BASH_SUBSHELL == 0 )); then - echo -ne "$_title_escape ${PWD/#$HOME/~} " - printf "%s" "$*" - echo -ne "\007" + if [[ $1 == prompt-command ]]; then + return 0 fi + echo -ne "$_title_escape ${PWD/#$HOME/~} " + printf "%s" "$*" + echo -ne "\007" } # note, this wont work: