doronbehar / pistol

General purpose file previewer designed for Ranger, Lf to make scope.sh redundant

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

image previews

luisdavim opened this issue · comments

Any plans to add image previews?

Create ~/.config/pistol/pistol.conf with the line

image/* <your image handling application>

eg., mine is image/* kitty +kitten icat %s

Although I did run into an issue when using this with ranger where the image was being shown at full size. Many of my images are larger than my screen, so all of ranger ends up being hidden. I don't actually know enough about how ranger passes parameters to kitty for image sizing to reproduce it for pistol.

Any plans to add image previews?

Just like Lf, I don't plan to support Image previews officially. I will keep this issue open so maybe someone will put his ideas here or something.

I will suggest though, maybe to try out Gnome sushi for this purpose.

hate to necrobump, but would like this also, really want to use LF fulltime but img previews are so convenient

I use the scope script on Lf, but perhaps the method described by @b33rcity can be applied with the program I use for images which is chafa, which previews pics in ANSI/Unicode.

The relevant line in my dots is
image/*) chafa --fill=block --symbols=block -c 256 -s 80x"${HEIGHT}" "${FILE_PATH}" || exit 1;;

I have a setup that assumes Kitty and has both image previews, and thumbnail previews for videos. Let me just share it.

pistol.conf:

video/* kitty_vidthumb %pistol-filename%                                                                                                                
image/* kitty +kitten icat %pistol-filename%

kitty_vidthumb:

#!/bin/sh
kitty +kitten icat --silent --transfer-mode=stream --stdin=no "$( vidthumb "$1")"

vidthumb:

#!/usr/bin/env bash

if ! [ -f "$1" ]; then
	exit 1
fi

if [[ "$(file -L -b --mime-type "$1")" != video/* ]]; then
	exit 1
fi

cache="$HOME/.cache/vidthumb"
index="$HOME/.cache/vidthumb/index.json"
movie="$(realpath "$1")"
thumbnail=""

mkdir -p "$cache"

if [ -f "$index" ]; then
	thumbnail="$(jq -r ". \"$movie\"" <"$index")"
	if [[ "$thumbnail" == "null" ]]; then
		thumbnail="$(uuidgen).jpg"
		json="$(jq -r --arg "$movie" "$thumbnail" ". + {\"$movie\": \"$thumbnail\"}" <"$index")"
		echo "$json" >"$index"
	fi
else
	thumbnail="$(uuidgen).jpg"
	echo "{\"$movie\": \"$thumbnail\"}" >"$index"
fi

if [ ! -f "$cache/$thumbnail" ]; then
	ffmpegthumbnailer -i "$movie" -o "$cache/$thumbnail" -s 0 2>/dev/null
fi

echo "$cache/$thumbnail"

The vidthumb script (which prints out the path to a movie's thumbnail, after first generating it, caching it in ~/.cache/vidthumb, and indexing it) uses jq, ffmpegthumbnailer and uuidgen.

I've set up a repository for this:
https://github.com/duganchen/kitty-pistol-previewer

If you just want image previews, the pistol.conf line is:

image/* kitty +kitten icat --silent --transfer-mode=stream --stdin=no %pistol-filename%

currently i am using this script for preview
may this help in implementation preview