Skip to content

Instantly share code, notes, and snippets.

@dunn
Last active October 12, 2015 10:48
Show Gist options
  • Save dunn/4015082 to your computer and use it in GitHub Desktop.
Save dunn/4015082 to your computer and use it in GitHub Desktop.
script to find papers
#!/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