Last active
October 12, 2015 10:48
-
-
Save dunn/4015082 to your computer and use it in GitHub Desktop.
script to find papers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# I have a lot of PDFs from JSTOR and elsewhere, and it's | |
# a chore to scroll them through manually. I've got a | |
# naming convention (frege1948.pdf, for example), so it's | |
# easy to search by filename and find the one I need. | |
PATH_TO_PAPERS_DIR="" | |
query="$1" | |
matches="" | |
counter=0 | |
matches=$(ag -g "$query.*\.pdf$" "$PATH_TO_PAPERS_DIR") | |
# this allows linebreaks in the pathnames | |
OLD="$IFS" | |
IFS=$'\n' | |
if [ "$matches" == "" ] | |
then | |
echo "---Nothing found." | |
exit 0 | |
else | |
echo "" | |
for title in $matches | |
do | |
echo "$counter --- $title" | |
(( counter++ )) | |
done | |
echo "" | |
echo -n '--- Which one do you want? (use `a` to open all) ' | |
read selection | |
if [ "$selection" == "a" ] | |
then | |
for title in $matches | |
do | |
open "$title" | |
done | |
else | |
counter=0 | |
for title in $matches | |
do | |
if [ "$counter" == "$selection" ] | |
then | |
open "$title" | |
fi | |
(( counter++ )) | |
done | |
fi | |
fi | |
IFS="$OLD" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment