bash: bunch of improvements
[distro-setup] / brc
diff --git a/brc b/brc
index 97f22e1ca96ecbdb65bdabb69aea925305850f1c..84837358700987d5510d9d36e2c555d9ffd25e70 100644 (file)
--- 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