bin: improve image handling
Also add sqlite3 support to b
This commit is contained in:
parent
2f9559afe6
commit
2c0e42dfa4
|
@ -12,6 +12,10 @@
|
||||||
# - text files are displayed through bat
|
# - text files are displayed through bat
|
||||||
# Automatically requests elevation through sudo when needed
|
# Automatically requests elevation through sudo when needed
|
||||||
|
|
||||||
|
test "$1" = "-v" &&
|
||||||
|
set -eo xtrace &&
|
||||||
|
shift
|
||||||
|
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
for last; do true; done
|
for last; do true; done
|
||||||
last=${last:-.}
|
last=${last:-.}
|
||||||
|
@ -26,15 +30,18 @@ fileinfo() {
|
||||||
tput setaf 6
|
tput setaf 6
|
||||||
for arg
|
for arg
|
||||||
do case "$arg" in (-*) continue;; esac
|
do case "$arg" in (-*) continue;; esac
|
||||||
$elevate file -E "$arg" &&
|
$elevate file -E "$arg"
|
||||||
ffprobe "$arg" 2>&1 | grep Duration | grep -v '00:00:00.04' | sed 's/, start:[^,]\+,/,/' ||
|
#probe="$($elevate ffprobe "$arg" 2>&1)"
|
||||||
|
#echo $probe | grep -v -e '00:00:00.04' -e 'ansi' &&
|
||||||
|
$elevate ffprobe "$arg" 2>&1 | grep "bitrate: ....\? " | sed 's/, start:[^,]\+,/,/' ||
|
||||||
stat --format '%A %s - birth %.10w mod %.10y' "$arg" | numfmt --field=2 --to=iec-i --padding=6 --suffix=B
|
stat --format '%A %s - birth %.10w mod %.10y' "$arg" | numfmt --field=2 --to=iec-i --padding=6 --suffix=B
|
||||||
done
|
done
|
||||||
|
tput sgr0
|
||||||
}
|
}
|
||||||
|
|
||||||
prefix=/tmp/b
|
prefix=/tmp/b
|
||||||
mkdir -p "$prefix"
|
mkdir -p "$prefix"
|
||||||
declare -a timg bat ls
|
declare -a timg timga bat ls
|
||||||
for arg; do
|
for arg; do
|
||||||
case "$arg" in (-*) args="$args $arg"; continue;; esac
|
case "$arg" in (-*) args="$args $arg"; continue;; esac
|
||||||
checkperm "$arg"
|
checkperm "$arg"
|
||||||
|
@ -47,7 +54,7 @@ for arg; do
|
||||||
;;
|
;;
|
||||||
(*\ video/*)
|
(*\ video/*)
|
||||||
suffix=_thumbs.jpg
|
suffix=_thumbs.jpg
|
||||||
mtn -i -t -W -D6 -b 0,6 -c $grid -w $(expr $(tput cols) '*' 20) \
|
mtn -i -t -W -r2 -D6 -b 0,6 -c $grid -w $(expr $(tput cols) '*' 20) \
|
||||||
-O $prefix -o $suffix "$arg" 2>/dev/null
|
-O $prefix -o $suffix "$arg" 2>/dev/null
|
||||||
timg -W "$prefix/$(basename "${arg%.*}")$suffix"
|
timg -W "$prefix/$(basename "${arg%.*}")$suffix"
|
||||||
;;
|
;;
|
||||||
|
@ -68,6 +75,7 @@ for arg; do
|
||||||
timg -g $(tput cols)x2 --auto-crop --upscale "$img"
|
timg -g $(tput cols)x2 --auto-crop --upscale "$img"
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
timga+=("$arg")
|
||||||
;;
|
;;
|
||||||
(*:\ *compress*|*\ archive*)
|
(*:\ *compress*|*\ archive*)
|
||||||
if test $# = 1
|
if test $# = 1
|
||||||
|
@ -77,7 +85,10 @@ for arg; do
|
||||||
bat+=("$tmpfile");;
|
bat+=("$tmpfile");;
|
||||||
esac; fi
|
esac; fi
|
||||||
;;
|
;;
|
||||||
(*) bat+=("$arg"); continue;;
|
(*:\ *database*) sqlite3 "$arg" ".tables";;
|
||||||
|
(*) bat+=("$arg")
|
||||||
|
timga+=("$arg")
|
||||||
|
continue;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -85,24 +96,25 @@ for arg; do
|
||||||
done
|
done
|
||||||
|
|
||||||
if test "$timg"; then
|
if test "$timg"; then
|
||||||
tput sgr0
|
$elevate timg -V --rotate=exif -g $(tput cols)x$(expr $(tput lines) / 2) \
|
||||||
$elevate timg --center -t0.3 $(test $# -gt 1 &&
|
$(test $# -gt 1 && echo "-t0.2 --center --title --grid=$(expr $(tput cols) / 20)x2") \
|
||||||
echo "--title --grid=$(expr $(tput cols) / 30)" ||
|
"${timg[@]}" "${timga[@]}" 2>/dev/null
|
||||||
echo "-g 60x$(expr $(tput lines) / 2)") "$@" 2>/dev/null
|
tput setaf 6
|
||||||
for img in "${timg[@]}"
|
for img in "${timg[@]}"
|
||||||
do printf "%11s %-30s %s\n" "$(identify -format "%wx%h" "$img")" "$img" "$(identify -precision 3 -format "%b %m %[bit-depth]-bit %[colorspace]" "$img")"
|
|
||||||
|
do ident="$(identify -ping -precision 3 -format "%wx%h %b %m %[bit-depth]-bit %[colorspace]" "$img")"
|
||||||
|
printf "%11s %-30s %s\n" "${ident%% *}" "$(basename "$img")" "${ident#* }"
|
||||||
done
|
done
|
||||||
|
tput sgr0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test "$bat"; then
|
if test "$bat"; then
|
||||||
tput sgr0
|
|
||||||
test $# -gt ${#bat[@]} && test -z "$args" &&
|
test $# -gt ${#bat[@]} && test -z "$args" &&
|
||||||
$elevate head "${bat[@]}" ||
|
$elevate head "${bat[@]}" | cut -c-$(echo "$(tput cols)*1.9" | bc | cut -d. -f1) ||
|
||||||
$elevate bat --style header --pager 'less -RF' $args "${bat[@]}"
|
$elevate bat --style header --pager 'less -RF' $args "${bat[@]}"
|
||||||
fileinfo "${bat[@]}"
|
fileinfo "${bat[@]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test "$ls"; then
|
if test "$ls"; then
|
||||||
tput sgr0
|
|
||||||
$elevate ls -l $(test $# -gt ${#ls[@]} && echo "-d") --color=always --human-readable --group-directories-first --file-type --dereference-command-line --all "${ls[@]}" | less -RF
|
$elevate ls -l $(test $# -gt ${#ls[@]} && echo "-d") --color=always --human-readable --group-directories-first --file-type --dereference-command-line --all "${ls[@]}" | less -RF
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
# Compare select terminal image viewers
|
# Compare select terminal image viewers
|
||||||
# Args: <height> [images]...
|
# Args: <height> [images]...
|
||||||
runti() {
|
set -x
|
||||||
which "$1" >/dev/null &&
|
size=10
|
||||||
highlight "$*" && "$@"
|
if test $# -eq 0
|
||||||
}
|
then args=$DATA/images/*.png
|
||||||
cols="$(expr $(tput cols) / $1 / 3 \| 1)"
|
else echo "$1" | grep -v -e "\." -e "/" && size=$1 && shift
|
||||||
runti timg --rotate=exif --title --grid=${cols} -g $(tput cols)x$(expr $1 \* $cols + 4) "${@:2}"
|
fi
|
||||||
runti viu --name -h $1 "${@:2}"
|
cols="$(expr $(tput cols) / $size / 3 \| 1)"
|
||||||
runti tiv -h $1 -c $(expr $cols + 1) "${@:2}"
|
timg --rotate=exif --title --grid=${cols} -g $(tput cols)x$(expr $size \* $cols + 4) "$@" $args
|
||||||
|
viu --name -h $size "$@" $args
|
||||||
|
tiv -h $size -c $(expr $cols + 1) "$@" $args
|
||||||
|
|
Loading…
Reference in New Issue