diff --git a/Examples.md b/Examples.md index 683268a..6ceb114 100644 --- a/Examples.md +++ b/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. ![](https://user-images.githubusercontent.com/1019692/34446795-12229072-ecac-11e7-856a-ec0df0de60ae.gif) -``` -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