#!/bin/sh
#
# lsbin - lsbin <DIR> lists ELF binaries in a directory, sorted by date modified
#
# useful for debugging `update-all` scripts to make sure compilation occurred.
# <DIR> defaults to $HOME/.local/bin if no args are provided.
#
# ---
# source: https://git.sr.ht/~seirdy/dotfiles

# binls will list all ELF binaries in the given directory,
# excluding old zsh versions
binls() {
  # shellcheck disable=SC2016 # these are regexes, not shell expansions
  fd -uu -t x -E 'zsh\.old' -E 'zsh-[0-9].*' -X file '{}' \
    | rg -e ':\s*ELF 64-bit LSB.*$' --replace '' | tr '\n' ' '
}

if [ -n "$1" ]; then
  bindir="$1"
else
  bindir="${HOME}/.local/bin"
fi

# ls the ELF binaries, sorted by date modified (reverse).
#
# display only these fields:
# - human-readable size
# - modification date
# - filename
cd "${bindir}" \
  && LC_TIME=en_US.UTF-8 binls \
  | xargs -L1 ls -hort --time-style=+'%m-%d %H:%M:%S' | cut -d' ' -f 4-
