Skip to content

Instantly share code, notes, and snippets.

@suvayu
Last active April 8, 2022 16:31
Show Gist options
  • Save suvayu/d6e0a5da746ea27ac770c7b744fac337 to your computer and use it in GitHub Desktop.
Save suvayu/d6e0a5da746ea27ac770c7b744fac337 to your computer and use it in GitHub Desktop.
Preview list of files
#!/bin/bash
# License: GPLv2
# set -o xtrace
if [[ -t 0 ]]; then
echo no stdin
exit 1
elif [[ ! -f $(which fzf 2> /dev/null) ]]; then
less
exit
fi
declare FILES=$(cat /dev/stdin)
# declare PAGER=$(which bat 2> /dev/null || echo less)
declare SELECTION
while true; do
SELECTION=$(
echo "${FILES}" | \
fzf --height 25 -0 -1 --disabled -e \
--bind 'q:abort,/:toggle-search' \
--preview="less {}" \
--preview-window=right:60% "${@}")
[[ -n $SELECTION ]] && less -N $SELECTION || break
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment