mirror of
https://github.com/ItsDrike/dotfiles.git
synced 2024-11-10 02:39:40 +00:00
Add ability to use pixterm for img previews
This commit is contained in:
parent
41522e8b0d
commit
00780218bd
|
@ -1,11 +1,21 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
readonly PREVIEW_ID="preview"
|
path="$1"
|
||||||
|
x="$2"
|
||||||
printf '{"action": "add", "identifier": "%s", "x": %d, "y": %d, "width": %d, "height": %d, "scaler": "contain", "scaling_position_x": 0.5, "scaling_position_y": 0.5, "path": "%s"}\n' \
|
y="$3"
|
||||||
"$PREVIEW_ID" "$2" "$3" "$4" "$5" "$1" > "$FIFO_UEBERZUG"
|
width="$4"
|
||||||
|
height="$5"
|
||||||
#declare -p -A cmd=([action]=add [identifier]="$PREVIEW_ID" \
|
PREVIEW_ID="preview"
|
||||||
# [x]="$2" [y]="$3" [max_width]="$4" [max_height]="$5" \
|
|
||||||
# [path]="$1") > "$FIFO_UEBERZUG"
|
|
||||||
|
|
||||||
|
if [ -n "$FIFO_UEBERZUG" ]; then
|
||||||
|
printf '{"action": "add", "identifier": "%s", "x": %d, "y": %d, "width": %d, "height": %d, "scaler": "contain", "scaling_position_x": 0.5, "scaling_position_y": 0.5, "path": "%s"}\n' \
|
||||||
|
"$PREVIEW_ID" "$x" "$y" "$width" "$height" "$path" > "$FIFO_UEBERZUG"
|
||||||
|
else
|
||||||
|
# Ueberzug isn't avialable, try to use pixterm
|
||||||
|
if command -v pixterm > /dev/null; then
|
||||||
|
pixterm -s 2 -tr "$x" -tc "$width" "$path"
|
||||||
|
else
|
||||||
|
>&2 echo "ueberzug not running, pixterm fallback not found!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# This script handles showing file-previews within lf.
|
# This script handles showing file-previews within lf.
|
||||||
|
|
||||||
# It can also show image previews using ueberzug, however
|
# It can also show image previews using ueberzug, however
|
||||||
# that requires lf to be start with a script that also starts
|
# that requires lf to be started with a script that also starts
|
||||||
# ueberzug alongside of it.
|
# ueberzug alongside of it.
|
||||||
# (In my dotfiles, this script is in '~/.local/bin/scripts/lfu')
|
# (In my dotfiles, this script is in '~/.local/bin/scripts/lfu')
|
||||||
|
# Alternatively, we could also handle ANSI previews with pixterms
|
||||||
|
# this will be in a pretty low quiality, but it will work without
|
||||||
|
# ueberzug. To enable this, change PIXTERM_ENABLED to 1.
|
||||||
|
# if both ueberzug and pixterm are enabled, ueberzug takes precedence.
|
||||||
|
PIXTERM_ENABLED=1
|
||||||
|
|
||||||
run_cmd() {
|
run_cmd() {
|
||||||
# Try to run given command, if it is installed.
|
# Try to run given command, if it is installed.
|
||||||
|
@ -77,7 +83,8 @@ media_handle() {
|
||||||
file="$1"
|
file="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
# Set ENABLED=1 if ueberzug is enabled
|
# Set ENABLED=1 if ueberzug or pixterm is enabled
|
||||||
|
command -v pixterm > /dev/null && [ "$PIXTERM_ENABLED" = 1 ] && ENABLED=1
|
||||||
[ -n "$FIFO_UEBERZUG" ] && [ -f "$draw_script" ] && ENABLED=1
|
[ -n "$FIFO_UEBERZUG" ] && [ -f "$draw_script" ] && ENABLED=1
|
||||||
|
|
||||||
case "$file" in
|
case "$file" in
|
||||||
|
@ -85,7 +92,7 @@ media_handle() {
|
||||||
if [ -n "$ENABLED" ]; then
|
if [ -n "$ENABLED" ]; then
|
||||||
draw_image $draw_script "$file"
|
draw_image $draw_script "$file"
|
||||||
else
|
else
|
||||||
echo "@@PREVIEW FALLBACK: Using mediainfo, ueberzug isn't aviable."
|
echo "@@PREVIEW FALLBACK: Using mediainfo, ueberzug isn't available."
|
||||||
run_cmd mediainfo "$file"
|
run_cmd mediainfo "$file"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Reference in a new issue