useful shell functions

source with

@ .bashrc
source $HOME/bin/auxifu.sh

# @ .zshrc
# emulate sh -c 'source ~/bin/auxifu.sh'
function urlquote {
  python3 -uc 'import sys; from urllib.parse import quote; sys.stdout.write(quote(sys.stdin.read()))'
}

Adjust directory mtime according to the latest file’s mtime there

function tadj {
    touch -r "$1/$(ls -1rt $1 | tail -n1)" "$1"
}

Get service IP for docker container – shell function

function dkr-ip {
  docker inspect --format '{{ .NetworkSettings.IPAddress }}' $@
}

Pull fresh images

function dkr-upd {
  for DIMG in $(docker images \
    | egrep "\b($(echo $@ | tr '[:blank:]' '|'))\b" \
    | sed -e 's/\s\+/:/g' | cut -d":" -f1,2 \
    | grep -v ':<none>$')
  do
    docker pull "$DIMG"
  done
}
Remote docker-load
usage: dkr-scp <file or image> <remote host>
function dkr-scp { (
  set -euo pipefail
  if [ -f "$1" ]; then
    cat "$1" \
    | tee >(sha256sum >&2) | ssh "$2" 'tee >(sha256sum >&2) >(docker load) >/dev/null'
  elif docker image inspect "$1" >/dev/null 2>&1; then
    docker save "$1" | gzip -c \
    | tee >(sha256sum >&2) | ssh "$2" 'tee >(sha256sum >&2) >(docker load) >/dev/null'
  else
    echo "Neither file nor image found with name '$1'"
  fi
) }
[Un]Scramblers
Do not forget to set/source required vars!
function un-ebin-all { (
  set -eu
  [ -f ~/.config/env-ebin ] && source ~/.config/env-ebin
  export EBINP

  ls *.ebin
  for F in *.ebin
  do
    set -x
    openssl enc -d -aes-256-cbc ${KEY_DERIVE_ALGOPT} -nosalt -pass 'env:EBINP' -in $F -out ${F/.ebin/}
    _F_STEM=$(py -c 'import pathlib, sys; sys.stdout.write(pathlib.Path(sys.argv[1]).stem)' "${F/.ebin/}")
    shasum -c ${_F_STEM}*.sha*
    set +x
  done
) }
function ebin { (
  set -eu
  [ -f ~/.config/env-ebin ] && source ~/.config/env-ebin
  export EBINP

  A="$1"
  F=$(py -c 'import pathlib, sys; sys.stdout.write(pathlib.Path(sys.argv[1]).stem)' "$A")
  if [ -d "$A" ]; then
    FA="${F}.tmp.tar"
    tar cf "${FA}" "$A"
  else
    FA="${A}"
  fi

  openssl enc -aes-256-cbc ${KEY_DERIVE_ALGOPT} -nosalt -pass 'env:EBINP' -in "$FA" -out "${F}.ebin"

  sha256sum "${F}.ebin" >"${F}.sha256"
  [ "$FA" != "$A" ] && rm -v "$FA"
  set +e
) }
function xzebin { (
  set -eu
  [ -f ~/.config/env-ebin ] && source ~/.config/env-ebin
  export EBINP

  A="$1"
  F=$(py -c 'import pathlib, sys; sys.stdout.write(pathlib.Path(sys.argv[1]).stem)' "$A")
  if [ -d "$A" ]; then
    FA="${F}.tmp.txz"
    XZ_OPT=-T0 tar cJf "${FA}" "$A"
  else
    xz -vkS '.tmp.xz' "$A"
    FA="${A}.tmp.xz"
  fi

  openssl enc -aes-256-cbc ${KEY_DERIVE_ALGOPT} -nosalt -pass 'env:EBINP' -in "$FA" -out "${F}.ebin"

  sha256sum "${F}.ebin" >"${F}.sha256"
  rm -v "$FA"
  set +e
) }