readd img preview
This commit is contained in:
parent
19512334b3
commit
4cb2f88603
|
|
@ -6,7 +6,7 @@ if [ -d "$1" ]; then
|
||||||
elif [ "$category" = text ]; then
|
elif [ "$category" = text ]; then
|
||||||
(bat -p --color=always "$1" || cat "$1") 2>/dev/null | head -1000
|
(bat -p --color=always "$1" || cat "$1") 2>/dev/null | head -1000
|
||||||
elif [ "$category" = image ]; then
|
elif [ "$category" = image ]; then
|
||||||
img2txt "$1"
|
command -v ueberzug 2&>/dev/null && bash $OMZ/lib/img_preview.sh "$1"|| img2txt "$1"
|
||||||
else
|
else
|
||||||
echo $1 is a $category file
|
echo $1 is a $category file
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# 用于在<tab>行为发生时获取当前的光标位置
|
||||||
|
|
||||||
|
exec < /dev/tty
|
||||||
|
oldstty=$(stty -g)
|
||||||
|
stty raw -echo min 0
|
||||||
|
echo -en "\033[6n" > /dev/tty
|
||||||
|
IFS=';' read -r -d R -a pos
|
||||||
|
stty $oldstty
|
||||||
|
row=$((${pos[0]:2} - 1))
|
||||||
|
col=$((${pos[1]} - 1))
|
||||||
|
echo "export row=$row" > $OMZ/cache/cursor
|
||||||
|
echo "export col=$col" >> $OMZ/cache/cursor
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
declare -r -x DEFAULT_PREVIEW_POSITION="right"
|
||||||
|
declare -r -x UEBERZUG_FIFO="$(mktemp --dry-run --suffix "fzf-$$-ueberzug")"
|
||||||
|
declare -r -x PREVIEW_ID="preview"
|
||||||
|
|
||||||
|
function start_ueberzug {
|
||||||
|
mkfifo "${UEBERZUG_FIFO}"
|
||||||
|
<"${UEBERZUG_FIFO}" \
|
||||||
|
ueberzug layer --parser bash --silent &
|
||||||
|
3>"${UEBERZUG_FIFO}" \
|
||||||
|
exec
|
||||||
|
}
|
||||||
|
|
||||||
|
function finalise {
|
||||||
|
3>&- \
|
||||||
|
exec
|
||||||
|
&>/dev/null \
|
||||||
|
rm "${UEBERZUG_FIFO}"
|
||||||
|
&>/dev/null \
|
||||||
|
kill $(jobs -p)
|
||||||
|
killall ueberzug
|
||||||
|
}
|
||||||
|
|
||||||
|
function draw_preview {
|
||||||
|
source $OMZ/cache/cursor
|
||||||
|
X=$(($COLUMNS / 2 + 2))
|
||||||
|
Y=$((row + 2))
|
||||||
|
if [ $Y -gt $((LINES - 11)) ]; then
|
||||||
|
Y=$((LINES - 11))
|
||||||
|
fi
|
||||||
|
|
||||||
|
>"${UEBERZUG_FIFO}" declare -A -p cmd=( \
|
||||||
|
[action]=add [identifier]="${PREVIEW_ID}" \
|
||||||
|
[x]="${X}" [y]="${Y}" \
|
||||||
|
[width]="$(($COLUMNS / 2 - 2))" [height]="10" \
|
||||||
|
[scaler]=forced_cover [scaling_position_x]=0.5 [scaling_position_y]=0.5 \
|
||||||
|
[path]="${@}")
|
||||||
|
}
|
||||||
|
|
||||||
|
trap finalise EXIT
|
||||||
|
start_ueberzug
|
||||||
|
draw_preview $*
|
||||||
|
sleep 999999
|
||||||
|
|
@ -211,6 +211,7 @@ fzf-tab-debug() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fzf-tab-complete() {
|
fzf-tab-complete() {
|
||||||
|
bash $OMZ/lib/get_cursor.sh
|
||||||
# this name must be ugly to avoid clashes
|
# this name must be ugly to avoid clashes
|
||||||
local -i _ftb_continue=1 _ftb_continue_last=0 _ftb_accept=0 ret=0
|
local -i _ftb_continue=1 _ftb_continue_last=0 _ftb_accept=0 ret=0
|
||||||
# hide the cursor until finishing completion, so that users won't see cursor up and down
|
# hide the cursor until finishing completion, so that users won't see cursor up and down
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue