Skip to content

Commit

Permalink
fix: improve pdf fuzzy opening (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Jan 29, 2023
1 parent df2b253 commit dcbc690
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 14 deletions.
57 changes: 53 additions & 4 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,18 @@
</dict>
</array>
<key>113F2026-78AB-41BA-8836-6145DE94CBEF</key>
<array/>
<array>
<dict>
<key>destinationuid</key>
<string>7FED238F-6F1B-440B-9FB3-5D9B520D67BF</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>1C0964D1-AA81-478A-B406-28E96DDD9E82</key>
<array>
<dict>
Expand Down Expand Up @@ -2180,6 +2191,35 @@ echo -n $dummyBib | pandoc --citeproc --read=markdown --write=plain --csl $csl -
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>alignment</key>
<integer>0</integer>
<key>backgroundcolor</key>
<string></string>
<key>fadespeed</key>
<integer>0</integer>
<key>fillmode</key>
<integer>0</integer>
<key>font</key>
<string></string>
<key>ignoredynamicplaceholders</key>
<false/>
<key>largetypetext</key>
<string>{query}</string>
<key>textcolor</key>
<string></string>
<key>wrapat</key>
<integer>50</integer>
</dict>
<key>type</key>
<string>alfred.workflow.output.largetype</string>
<key>uid</key>
<string>7FED238F-6F1B-440B-9FB3-5D9B520D67BF</string>
<key>version</key>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -2307,9 +2347,9 @@ echo -n $dummyBib | pandoc --citeproc --read=markdown --write=plain --csl $csl -
<key>note</key>
<string>fuzzy open PDF</string>
<key>xpos</key>
<real>955</real>
<real>950</real>
<key>ypos</key>
<real>1525</real>
<real>1535</real>
</dict>
<key>1B72EC4E-33E7-4144-B43B-3037510ADA3A</key>
<dict>
Expand Down Expand Up @@ -2569,6 +2609,15 @@ to set a hotkey for the citaiton picker.</string>
<key>ypos</key>
<real>985</real>
</dict>
<key>7FED238F-6F1B-440B-9FB3-5D9B520D67BF</key>
<dict>
<key>colorindex</key>
<integer>1</integer>
<key>xpos</key>
<real>1105</real>
<key>ypos</key>
<real>1535</real>
</dict>
<key>824D0711-2DC5-46B0-8EA1-BD0A74DF5AAA</key>
<dict>
<key>colorindex</key>
Expand Down Expand Up @@ -2900,7 +2949,7 @@ to set a hotkey for adding an Doi/ISBN</string>
</array>
<array>
<string>default app for .bib files</string>
<string>default</string>
<string>default app for .bib files</string>
</array>
</array>
</dict>
Expand Down
22 changes: 13 additions & 9 deletions scripts/fuzzy-open-pdf.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#!/bin/zsh
PDF_FOLDER="${pdf_folder/#\~/$HOME}"
CITEKEY="$*"
# shellcheck disable=SC2001
CITEKEY_ALT=$(echo "$CITEKEY" | sed 's/\([[:digit:]]...\)/_\1/') # try old naming pattern of PDFs

cd "$PDF_FOLDER" || return 1

PDF_LIST=$(find . -maxdepth 3 -type f -name "*.pdf")
if (echo "$PDF_LIST" | grep -qi "$CITEKEY") ; then
FILE_PATH=$(echo "$PDF_LIST" | grep -i "$CITEKEY" | head -n1)
if [[ -d "$PDF_FOLDER" ]]; then
cd "$PDF_FOLDER"
else
FILE_PATH=$(echo "$PDF_LIST" | grep -i "$CITEKEY_ALT" | head -n1)
echo "$PDF_FOLDER does not exist"
return 1
fi

open "$FILE_PATH"
FILE_PATH=$(find . -maxdepth 3 -type f -name "*.pdf" | grep -i $CITEKEY | head -n1)

if [[ -f "$FILE_PATH" ]]; then
open "$FILE_PATH"
else
echo "No PDF for \"$CITEKEY\" found."
echo
echo "Make sure you have entered the correct pdf folder in the settings and named the PDF file correctly."
fi
2 changes: 1 addition & 1 deletion scripts/open-entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ elif [[ "$open_entries_in" == "neovim & alacritty" ]]; then
elif [[ "$open_entries_in" == "Zotero" ]]; then
# INFO "bbt:" ensures that the item is opened in the personal library https://github.com/chrisgrieser/alfred-bibtex-citation-picker/issues/20#issuecomment-1406495450
open "zotero://select/items/bbt:@$CITEKEY"
elif [[ "$open_entries_in" == "default" ]]; then
elif [[ "$open_entries_in" == "default app for .bib files" ]]; then
# passing line arguments for the few apps that could parse it
open "$LIBRARY" --env=LINE=$LINE_NO
fi
Expand Down

0 comments on commit dcbc690

Please sign in to comment.