summaryrefslogtreecommitdiff
path: root/scripts/fifo/fzf-fifo
diff options
context:
space:
mode:
authorpants <niklasjo2004@gmail.com>2026-09-21 14:18:06 -0700
committerpants <niklasjo2004@gmail.com>2026-09-21 14:18:06 -0700
commit83d5ba42f8a98fc0df177efef4333f74a0481f61 (patch)
tree6f1fcff64ec9adb2fc51a7cfcc451eb22a103fb3 /scripts/fifo/fzf-fifo
Diffstat (limited to 'scripts/fifo/fzf-fifo')
-rwxr-xr-xscripts/fifo/fzf-fifo45
1 files changed, 45 insertions, 0 deletions
diff --git a/scripts/fifo/fzf-fifo b/scripts/fifo/fzf-fifo
new file mode 100755
index 0000000..a9d5d20
--- /dev/null
+++ b/scripts/fifo/fzf-fifo
@@ -0,0 +1,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