>>107694841
fzf_preview_wrapper
#!/bin/env bash
# place the following in your shell environment
# export FZF_MPV_PIDFILE="${XDG_CACHE_HOME:-$HOME/.cache}/fzf_mpv_preview.pid"
# Base from environment variable, fallback to default
BASE_PIDFILE="${FZF_MPV_PIDFILE:-${XDG_CACHE_HOME:-$HOME/.cache}/fzf_mpv_preview}"
# Dynamic per-instance PID file ($$ is the PID of this script invocation)
PIDFILE="${BASE_PIDFILE}_$$.pid"
# Ensure cache directory exists
mkdir -p "$(dirname "$BASE_PIDFILE")"
# Kill previous preview instance
if [[ -f "$PIDFILE" ]]; then
old_pid=$(cat "$PIDFILE")
if kill "$old_pid" 2>/dev/null; then
# echo "Closed previous mpv preview (PID $old_pid)"
true
else
# Stale PID file
rm -f "$PIDFILE"
fi
fi
if [[ -d "$1" ]]; then
eza --color=always --icons -sextension --group-directories-first -TL3 "$1"
elif [[ -f "$1" ]]; then
mimetype=$(file --dereference --brief --mime-type -- "$1")
case "$mimetype" in
video/*)
mpv \
--pause \
--keep-open=yes \
--autofit-larger=30%x30% \
--title="Preview: $(basename "$1")" \
--x11-name="mpv_preview" \
"$1" &
echo $! > "$PIDFILE"
;;
image/*)
viu "$1"
;;
audio/*)
# Placeholder for audio files
# mpv --no-video ... or another player
;;
application/pdf | application/epub+zip)
# Placeholder for PDFs, ePUBs
# zathura "$1" &
;;
text/* | inode/x-empty)
nvimpager -c "$1"
;;
*)
rg --binary . "$1"
;;
esac
fi