init
This commit is contained in:
45
scripts/fifo/fzf-fifo
Executable file
45
scripts/fifo/fzf-fifo
Executable file
@ -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
|
||||
31
scripts/fifo/img-fifo
Executable file
31
scripts/fifo/img-fifo
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This is a simple script that allows you to use ueberzugpp to
|
||||
# preview images in the terminal by providing the x and y
|
||||
# coordinates of the image, the width and height of the image,
|
||||
# and the path to the image file, with $1, $2, $3, $4 and $5
|
||||
# as arguments, respectively.
|
||||
# Example usage:
|
||||
# ./img-fifo 0 0 30 30 image.jpg
|
||||
# Use Ctrl+C to exit.
|
||||
|
||||
FIFO="/tmp/preview_fifo"
|
||||
[ -p "$FIFO" ] || mkfifo "$FIFO"
|
||||
|
||||
start_ueberzugpp() {
|
||||
ueberzugpp layer --silent <"$FIFO" &
|
||||
exec 3>"${FIFO}"
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
rm -f "$FIFO"
|
||||
}
|
||||
trap cleanup HUP INT QUIT TERM EXIT
|
||||
|
||||
preview_image() {
|
||||
echo '{"path": "'"$5"'", "action": "add", "identifier": "img-fifo", "x": "'"$1"'", "y": "'"$2"'", "width": "'"$3"'", "height": "'"$4"'"}' >"$FIFO"
|
||||
}
|
||||
|
||||
start_ueberzugpp
|
||||
preview_image "$1" "$2" "$3" "$4" "$5"
|
||||
wait
|
||||
Reference in New Issue
Block a user