lf stuff
This commit is contained in:
parent
12377b185f
commit
d9834ae4ec
6 changed files with 48 additions and 75 deletions
4
.config/lf/scripts/cleaner
Executable file
4
.config/lf/scripts/cleaner
Executable file
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
if [ -n "$FIFO_UEBERZUG" ]; then
|
||||
printf '{"action": "remove", "identifier": "preview"}\n' >"$FIFO_UEBERZUG"
|
||||
fi
|
|
@ -1,67 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
clear_screen() {
|
||||
printf '\e[%sH\e[9999C\e[1J%b\e[1;%sr' \
|
||||
"$((LINES-2))" "${TMUX:+\e[2J}" "$max_items"
|
||||
}
|
||||
|
||||
# Get a file's mime_type.
|
||||
mime_type=$(file -bi "$1")
|
||||
|
||||
# File isn't an image file, give warning.
|
||||
if [[ $mime_type != image/* ]]; then
|
||||
lf -remote "send $id echoerr 'Not an image'"
|
||||
exit
|
||||
fi
|
||||
|
||||
w3m_paths=(/usr/{local/,}{lib,libexec,lib64,libexec64}/w3m/w3mi*)
|
||||
read -r w3m _ < <(type -p w3mimgdisplay "${w3m_paths[@]}")
|
||||
read -r LINES COLUMNS < <(stty size)
|
||||
|
||||
# Get terminal window size in pixels and set it to WIDTH and HEIGHT.
|
||||
export $(xdotool getactivewindow getwindowgeometry --shell)
|
||||
|
||||
# Get the image size in pixels.
|
||||
read -r img_width img_height < <("$w3m" <<< "5;${CACHE:-$1}")
|
||||
|
||||
((img_width > WIDTH)) && {
|
||||
((img_height=img_height*WIDTH/img_width))
|
||||
((img_width=WIDTH))
|
||||
}
|
||||
|
||||
((img_height > HEIGHT)) && {
|
||||
((img_width=img_width*HEIGHT/img_height))
|
||||
((img_height=HEIGHT))
|
||||
}
|
||||
|
||||
# Variable needed for centering image.
|
||||
HALF_HEIGHT=$(expr $HEIGHT / 2)
|
||||
HALF_WIDTH=$(expr $WIDTH / 2)
|
||||
HALF_IMG_HEIGHT=$(expr $img_height / 2)
|
||||
HALF_IMG_WIDTH=$(expr $img_width / 2)
|
||||
X_POS=$(expr $HALF_WIDTH - $HALF_IMG_WIDTH)
|
||||
Y_POS=$(expr $HALF_HEIGHT - $HALF_IMG_HEIGHT)
|
||||
|
||||
clear_screen
|
||||
# Hide the cursor.
|
||||
printf '\e[?25l'
|
||||
|
||||
# Display the image.
|
||||
printf '0;1;%s;%s;%s;%s;;;;;%s\n3;\n4\n' \
|
||||
${X_POS:-0} \
|
||||
${Y_POS:-0} \
|
||||
"$img_width" \
|
||||
"$img_height" \
|
||||
"${CACHE:-$1}" | "$w3m" &>/dev/null
|
||||
|
||||
# Wait for user input.
|
||||
read -ern 1
|
||||
|
||||
# Clear the image.
|
||||
printf '6;%s;%s;%s;%s\n3;' \
|
||||
"${X_POS:-0}" \
|
||||
"${Y_POS:-0}" \
|
||||
"$WIDTH" \
|
||||
"$HEIGHT" | "$w3m" &>/dev/null
|
||||
|
||||
clear_screen
|
6
.config/lf/scripts/image
Executable file
6
.config/lf/scripts/image
Executable file
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
if [ -n "$FIFO_UEBERZUG" ]; then
|
||||
path="$(printf '%s' "$1" | sed 's/\\/\\\\/g;s/"/\\"/g')"
|
||||
printf '{"action": "add", "identifier": "preview", "x": %d, "y": %d, "width": %d, "height": %d, "scaler": "contain", "scaling_position_x": 0.5, "scaling_position_y": 0.5, "path": "%s"}\n' \
|
||||
"$4" "$5" "$2" "$3" "$1" >"$FIFO_UEBERZUG"
|
||||
fi
|
|
@ -1,6 +1,36 @@
|
|||
#!/bin/sh
|
||||
case "$1" in
|
||||
*.png|*.jpg|*.jpeg|*.mp4|*.mkv) mediainfo "$1";;
|
||||
*) bat "$1";;
|
||||
*.md) glow -p -s dark "$1";;
|
||||
|
||||
draw() {
|
||||
~/.config/lf/scripts/image "$@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
cache() {
|
||||
if [ -f "$1" ]; then
|
||||
draw "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
case "$(file --dereference --brief --mime-type -- "$1")" in
|
||||
text/*) bat --terminal-width "$4" -f "$1" ;;
|
||||
image/*|video/*) mediainfo "$1" ;;
|
||||
# image/*)
|
||||
# [ -n "$FIFO_UEBERZUG" ] &&
|
||||
# orientation="$(identify -format '%[EXIF:Orientation]\n' -- "$file")"
|
||||
# if [ -n "$orientation" ] && [ "$orientation" != 1 ]; then
|
||||
# cache="$(hash "$file").jpg"
|
||||
# cache "$cache" "$@"
|
||||
# convert -- "$file" -auto-orient "$cache"
|
||||
# draw "$cache" "$@"
|
||||
# else
|
||||
# draw "$file" "$@"
|
||||
# fi
|
||||
# ;;
|
||||
esac
|
||||
|
||||
# case "$1" in
|
||||
# *.png|*.jpg|*.jpeg|*.mp4|*.mkv) mediainfo "$1";;
|
||||
# *) bat "$1";;
|
||||
# *.md) glow -p -s dark "$1";;
|
||||
# esac
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue