Skip to content

Instantly share code, notes, and snippets.

@uncomfyhalomacro
Last active March 29, 2022 09:10
Show Gist options
  • Save uncomfyhalomacro/05852386680cd507f258048806cfeeab to your computer and use it in GitHub Desktop.
Save uncomfyhalomacro/05852386680cd507f258048806cfeeab to your computer and use it in GitHub Desktop.
#!/bin/sh
# Uses fd - https://github.com/sharkdp/fd
# Uses epub2txt2 - https://github.com/kevinboone/epub2txt2
# Uses pdftotext from poppler
DOC="$HOME/Documents"
export DOC
tmp_pdf_file="$(mktemp)"
export tmp_pdf_file
book="$(fd -p "${DOC}" -e ".pdf" -e ".epub" -0 | xargs -0 sh -c 'for f; do echo "${f#"./Documents/"}"; done' | fzf --sync -e -i --prompt='read book: ' --preview '
tmpstuff={}
if [ "${tmpstuff: -4}" = ".pdf" ]
then
pdftotext "$HOME/Documents/$tmpstuff" "$tmp_pdf_file"
else
epub2txt "$HOME/Documents/$tmpstuff" > "$tmp_pdf_file"
fi
bat ${tmp_pdf_file} -p
')"
export book
rm "${tmp_pdf_file}"
[ -z "${book}" ] && exit
command="zathura \"${DOC}/${book}\""
setsid /bin/sh -c "${command}" &
sleep 0.3s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment