bin/b: group related types and show audio waveforms

This commit is contained in:
xeruf 2021-12-01 16:50:46 +01:00
parent bcc4c85c37
commit f6b3ad300e
1 changed files with 55 additions and 38 deletions

View File

@ -30,42 +30,59 @@ fileinfo() {
done done
} }
case "$mime" in prefix=/tmp/b
(*\ inode/directory\;*) tput sgr0 && mkdir -p "$prefix"
$(test -x "$last" || echo "sudo") ls -l --color=always --human-readable --group-directories-first --file-type --dereference-command-line --all "$@" | less -RF;; declare -a timg bat ls
(*binary|*-8bit) for arg; do
prefix=/tmp/b case "$arg" in (-*) args="$args $arg" continue;; esac
mkdir -p "$prefix" checkperm "$arg"
for arg; do grid=$(expr $(tput cols) / 20)
case "$arg" in (-*) continue;; esac case "$mime" in
checkperm "$arg" (*\ application/pdf\;*)
fileinfo "$arg" out="$prefix/$(basename "$arg")"
grid=$(expr $(tput cols) / 20) test -f "$out-1.png" || pdftoppm -r 70 "$arg" "$out" -l $(expr $grid '*' 2)
case "$mime" in timg -W --grid=$grid "$out"*
(*\ application/pdf\;*) ;;
out="$prefix/$(basename "$arg")" (*\ video/*)
test -f "$out-1.png" || pdftoppm -r 70 "$arg" "$out" -l $(expr $grid '*' 2) suffix=_thumbs.jpg
timg -W --grid=$grid "$out"* mtn -i -t -W -D6 -b 0,6 -c $grid -w $(expr $(tput cols) '*' 20) -O $prefix -o $suffix "$arg" 2>/dev/null
;; timg -W "$prefix/$(basename "${arg%.*}")$suffix"
(*\ video/*) ;;
suffix=_thumbs.jpg (*\ audio/*)
mtn -i -t -W -D6 -b 0,6 -c $grid -w $(expr $(tput cols) '*' 20) -O $prefix -o $suffix "$arg" 2>/dev/null img="$prefix/$arg.png"
timg -W "$prefix/$(basename "${arg%.*}")$suffix" find "$img" -not -empty 2>/dev/null | grep --quiet . ||
;; audiowaveform --quiet --pixels-per-second 5 --height 40 --width 2000 \
(*) --background-color 000000 --waveform-color 99BBFF --axis-label-color 000000 \
case "$(file "$arg")" in --input-filename "$arg" --output-format png >"$img" &&
(*:\ *compress*) /usr/share/nvim/runtime/macros/less.sh "$arg";; timg -g $(tput cols)x2 --upscale "$img"
(*:\ *\ image\ data*) timg --center $(test $# -gt 1 && ;;
echo "--title --grid=$(expr $(tput cols) / 30)" || (*\ image/*)
echo "-g 60x$(expr $(tput lines) / 2)") "$@" timg+=("$arg"); continue;;
exit $?;; (*\ inode/directory\;*)
esac ls+=("$arg"); continue;;
;; (*)
case "$(file "$arg")" in
(*:\ *compress*) /usr/share/nvim/runtime/macros/less.sh "$arg";;
(*) bat+=("$arg"); continue;;
esac esac
done ;;
;; esac
(*) fileinfo "$arg"
fileinfo "$@" done
$elevate bat --style header "$@" --pager 'less -RF'
;; if test "$timg"; then
esac $elevate timg --center -t0.3 $(test $# -gt 1 &&
echo "--title --grid=$(expr $(tput cols) / 30)" ||
echo "-g 60x$(expr $(tput lines) / 2)") "$@" 2>/dev/null || true
fileinfo "${timg[@]}"
fi
if test "$bat"; then
$elevate bat --style header --pager 'less -RF' $args "${bat[@]}"
fileinfo "${bat[@]}"
fi
if test "$ls"; then
tput sgr0
$(test -x "$arg" || echo "sudo") ls -l $(test $# -gt ${#ls[@]} && echo "-d") --color=always --human-readable --group-directories-first --file-type --dereference-command-line --all "${ls[@]}" | less -RF
fi