Skip to content

Commit

Permalink
entry deletion now creates a backup and informs notifies on problems
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Mar 15, 2022
1 parent 84cb6d2 commit a86f903
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -1386,9 +1386,9 @@ echo -n $dummyBib | pandoc --citeproc --read=markdown --write=plain --csl $csl -
<key>removeextension</key>
<false/>
<key>text</key>
<string>@{query}</string>
<string>{query}</string>
<key>title</key>
<string>Entry deleted from BibTeX Library</string>
<string>{var:citekey} deleted from BibTeX Library</string>
</dict>
<key>type</key>
<string>alfred.workflow.output.notification</string>
Expand Down
14 changes: 12 additions & 2 deletions scripts/delete_entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@
# shellcheck disable=SC2154
CITEKEY="${citekey/@/}"
LIBRARY="${bibtex_library_path/#\~/$HOME}"
ENTRIES_BEFORE=$(grep -c -E "@.*{" "$LIBRARY")

# deletes from a line matching the citekey to the next "}", https://stackoverflow.com/a/14492880
sed -i '' "/{$CITEKEY,/,/}$/d" "$LIBRARY"
# works with formatting from BibDesk and from Bookends
sed -i '.bak' "/{$CITEKEY,/,/}$/d" "$LIBRARY"

ENTRIES_AFTER=$(grep -c -E "@.*{" "$LIBRARY")
DIFFERENCE=$((ENTRIES_BEFORE - ENTRIES_AFTER))

# pass for notication in Alfred
echo -n "$CITEKEY"
if [[ $DIFFERENCE == 1 ]]; then
echo "Library now has $ENTRIES_AFTER entries."
mv -f "$LIBRARY.bak" ~./Trash
else
echo "Error, deleted $DIFFERENCE citations. Check Backup file (ending with .bak) in library location."
fi

0 comments on commit a86f903

Please sign in to comment.