blob: a9d5d209a5c4009db5c73c128cc70431c4128c86 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#!/bin/sh
# This is a simple script that allows you to have image preview
# in fzf, using ueberzugpp with fifo. For this script to work
# you must add it to path, because it requires to call itself
# during the preview process in fzf (line 42 -> $0).
# Example usage:
# ls | fzf-fifo
# find $HOME/pix/ -type f -iname "*.jpg" | fzf-fifo
FIFO="/tmp/fzf_preview_fifo"
[ -p "$FIFO" ] || mkfifo "$FIFO"
start_ueberzugpp() {
ueberzugpp layer --silent <"$FIFO" &
exec 3>"${FIFO}"
}
cleanup() {
exec 3>&-
}
trap cleanup HUP INT QUIT TERM EXIT
preview_image() {
echo '{"path": "'"$1"'", "action": "add", ''"identifier": "fzfpreview", '\
'"x": "'"$FZF_PREVIEW_LEFT"'", "y": "'"$FZF_PREVIEW_TOP"'", '\
'"width": "'"$FZF_PREVIEW_COLUMNS"'", "height": "'"$FZF_PREVIEW_LINES"'"}' \
>"$FIFO"
}
case "$1" in
-W)
shift
preview_image "$@"
exit
;;
esac
main() {
start_ueberzugpp
selected_image=$(fzf --preview "$0 -W {}" --preview-window=up:60%:wrap)
[ -n "$selected_image" ] && echo "Selected image: $selected_image"
rm "$FIFO"
}
main
|