mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-18 08:13:40 -05:00
Link to updated (external) script for finding academic PDFs using fzf.
40
Examples.md
40
Examples.md
@@ -1085,43 +1085,5 @@ The selected file is then opened by the default pdf viewer.
|
||||
Requires the [pdftotext](https://en.wikipedia.org/wiki/Pdftotext) command line tool. Tested on Ubuntu 17.10 on bash and zsh.
|
||||
|
||||

|
||||
```
|
||||
|
||||
p () {
|
||||
local DIR open
|
||||
declare -A already
|
||||
DIR="${HOME}/.cache/pdftotext"
|
||||
mkdir -p "${DIR}"
|
||||
if [ "$(uname)" = "Darwin" ]; then
|
||||
open=open
|
||||
else
|
||||
open="gio open"
|
||||
fi
|
||||
|
||||
{
|
||||
ag -g ".pdf$"; # fast, without pdftotext
|
||||
ag -g ".pdf$" \
|
||||
| while read -r FILE; do
|
||||
local EXPIRY HASH CACHE
|
||||
HASH=$(md5sum "$FILE" | cut -c 1-32)
|
||||
# Remove duplicates (file that has same hash as already seen file)
|
||||
[ ${already[$HASH]+abc} ] && continue # see https://stackoverflow.com/a/13221491
|
||||
already[$HASH]=$HASH
|
||||
EXPIRY=$(( 86400 + $RANDOM * 20 )) # 1 day (86400 seconds) plus some random
|
||||
CMD="pdftotext -f 1 -l 1 '$FILE' - 2>/dev/null | tr \"\n\" \"_\" "
|
||||
CACHE="$DIR/$HASH"
|
||||
test -f "${CACHE}" && [ $(expr $(date +%s) - $(date -r "$CACHE" +%s)) -le $EXPIRY ] || eval "$CMD" > "${CACHE}"
|
||||
echo -e "$FILE\t$(cat ${CACHE})"
|
||||
done
|
||||
} | fzf -e -d '\t' \
|
||||
--preview-window up:75% \
|
||||
--preview '
|
||||
v=$(echo {q} | tr " " "|");
|
||||
echo {1} | grep -E "^|$v" -i --color=always;
|
||||
pdftotext -f 1 -l 1 {1} - | grep -E "^|$v" -i --color=always' \
|
||||
| awk 'BEGIN {FS="\t"; OFS="\t"}; {print "\""$1"\""}' \
|
||||
| xargs $open > /dev/null 2> /dev/null
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
The script is now given at https://github.com/bellecp/fast-p
|
||||
|
||||
Reference in New Issue
Block a user