Last active
June 26, 2022 14:45
-
-
Save jag3773/5797912d1fc6616e55af88a6d10c6d41 to your computer and use it in GitHub Desktop.
Scripture Reference Fixer for Obsidian
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
#!/usr/bin/env bash | |
# This turns natural references into wiki link references like this: | |
# Genesis 12:3 -> [[Genesis 12#12:3]] | |
# Psalm 119:9-11 -> [[Psalm 119#119:9-11]] | |
# 1 John 3 -> [[1 John 3]] | |
# First John 1 -> [[1 John 1]] | |
# Put this file into .git/hooks/ and it will run every time you | |
# commit into your repository. Make sure it is executable, you can run | |
# chmod +x .git/hooks/pre-commit | |
# Requires the gsed utility on Mac. For Linux, change `gsed` to `sed` below (line 63). | |
### BEGIN USER CONFIG ### | |
# You need to fill in the path to your git-backed Obsidian vault. | |
PATHTOVAULT= | |
# Where are your markdown files? Uncomment the option you want | |
#MARKDOWNFILES="*/*.md" # look 1 directory deep | |
#MARKDOWNFILES="resources/notes/*.md" # only look in the notes directory | |
### END USER CONFIG ### | |
cd "$PATHTOVAULT" | |
GREPREGEX='[0-9][0-9]*[ ,;.:?)]' | |
SEDVSREGEX='\([0-9]*\)\(:[0-9]*[-0-9]*\)/\[\[\1 \2#\2\3\]\]/g' | |
SEDCPREGEX='\([0-9]*\)\([ ,;.]\)/\[\[\1 \2\]\]\3/g' | |
IFS=$'\n' | |
for x in `/usr/bin/grep -l -i \ | |
-e "[123] [JPTCSKjptcsk][a-z]* $GREPREGEX" \ | |
-e "[Ff]irst [JPTCSKjptcsk][a-z]* $GREPREGEX" \ | |
-e "[Ss]econd [JPTCSKjptcsk][a-z]* $GREPREGEX" \ | |
-e "[Tt]hird [JPTCSKjptcsk][a-z]* $GREPREGEX" \ | |
-e "[123][snr][td] [JPTCSKjptcsk][a-z]* $GREPREGEX" \ | |
-e "Genesis $GREPREGEX" -e "Exodus $GREPREGEX" \ | |
-e "Leviticus $GREPREGEX" -e "Numbers $GREPREGEX" \ | |
-e "Deuteronomy $GREPREGEX" -e "Joshua $GREPREGEX" \ | |
-e "Judges $GREPREGEX" -e "Ruth $GREPREGEX" \ | |
-e "Ezra $GREPREGEX" -e "Nehemiah $GREPREGEX" \ | |
-e "Esther $GREPREGEX" -e "Job $GREPREGEX" \ | |
-e "Psalms* $GREPREGEX" -e "Proverbs $GREPREGEX" \ | |
-e "Ecclesiastes $GREPREGEX" -e "Song of Solomon $GREPREGEX" \ | |
-e "Isaiah $GREPREGEX" -e "Jeremiah $GREPREGEX" \ | |
-e "Lamentations $GREPREGEX" -e "Ezekiel $GREPREGEX" \ | |
-e "Daniel $GREPREGEX" -e "Hosea $GREPREGEX" \ | |
-e "Joel $GREPREGEX" -e "Amos $GREPREGEX" \ | |
-e "Obadiah $GREPREGEX" -e "Jonah $GREPREGEX" \ | |
-e "Micah $GREPREGEX" -e "Nahum $GREPREGEX" \ | |
-e "Habakkuk $GREPREGEX" -e "Zephaniah $GREPREGEX" \ | |
-e "Haggai $GREPREGEX" -e "Zechariah $GREPREGEX" \ | |
-e "Malachi $GREPREGEX" -e "Matthew $GREPREGEX" \ | |
-e "Mark $GREPREGEX" -e "Luke $GREPREGEX" \ | |
-e "John $GREPREGEX" -e "Acts $GREPREGEX" \ | |
-e "Romans $GREPREGEX" -e "Galatians $GREPREGEX" \ | |
-e "Ephesians $GREPREGEX" -e "Philippians $GREPREGEX" \ | |
-e "Colossians $GREPREGEX" -e "Titus $GREPREGEX" \ | |
-e "Philemon $GREPREGEX" -e "Hebrews $GREPREGEX" \ | |
-e "James $GREPREGEX" -e "Jude $GREPREGEX" -e "Revelation $GREPREGEX" \ | |
${MARKDOWNFILES}`; do | |
gsed -i \ | |
-e "s/\([123] [JPTCSKjptcsk][a-z]*\) $SEDVSREGEX" \ | |
-e "s/[Ff]irst \([JPTCSKjptcsk][a-z]*\) \([0-9]*\)\(:[0-9]*[-0-9]*\)/\[\[1 \1 \2#\2\3\]\]/g" \ | |
-e "s/[Ss]econd \([JPTCSKjptcsk][a-z]*\) \([0-9]*\)\(:[0-9]*[-0-9]*\)/\[\[2 \1 \2#\2\3\]\]/g" \ | |
-e "s/[Tt]hird \([JPTCSKjptcsk][a-z]*\) \([0-9]*\)\(:[0-9]*[-0-9]*\)/\[\[3 \1 \2#\2\3\]\]/g" \ | |
-e "s/\([123]\)[snr][td] \([JPTCSKjptcsk][a-z]*\) \([0-9]*\)\(:[0-9]*[-0-9]*\)/\[\[\1 \2 \3#\3\4\]\]/g" \ | |
-e "s/\(Genesis\) $SEDVSREGEX" -e "s/\(Exodus\) $SEDVSREGEX" \ | |
-e "s/\(Leviticus\) $SEDVSREGEX" -e "s/\(Numbers\) $SEDVSREGEX" \ | |
-e "s/\(Deuteronomy\) $SEDVSREGEX" -e "s/\(Joshua\) $SEDVSREGEX" \ | |
-e "s/\(Judges\) $SEDVSREGEX" -e "s/\(Ruth\) $SEDVSREGEX" \ | |
-e "s/\(Ezra\) $SEDVSREGEX" -e "s/\(Nehemiah\) $SEDVSREGEX" \ | |
-e "s/\(Esther\) $SEDVSREGEX" -e "s/\(Job\) $SEDVSREGEX" \ | |
-e "s/\(Psalms*\) $SEDVSREGEX" -e "s/\(Proverbs\) $SEDVSREGEX" \ | |
-e "s/\(Ecclesiastes\) $SEDVSREGEX" -e "s/\(Song of Solomon\) $SEDVSREGEX" \ | |
-e "s/\(Isaiah\) $SEDVSREGEX" -e "s/\(Jeremiah\) $SEDVSREGEX" \ | |
-e "s/\(Lamentations\) $SEDVSREGEX" -e "s/\(Ezekiel\) $SEDVSREGEX" \ | |
-e "s/\(Daniel\) $SEDVSREGEX" -e "s/\(Hosea\) $SEDVSREGEX" \ | |
-e "s/\(Joel\) $SEDVSREGEX" -e "s/\(Amos\) $SEDVSREGEX" \ | |
-e "s/\(Obadiah\) $SEDVSREGEX" -e "s/\(Jonah\) $SEDVSREGEX" \ | |
-e "s/\(Micah\) $SEDVSREGEX" -e "s/\(Nahum\) $SEDVSREGEX" \ | |
-e "s/\(Habakkuk\) $SEDVSREGEX" -e "s/\(Zephaniah\) $SEDVSREGEX" \ | |
-e "s/\(Haggai\) $SEDVSREGEX" -e "s/\(Zechariah\) $SEDVSREGEX" \ | |
-e "s/\(Malachi\) $SEDVSREGEX" -e "s/\(Matthew\) $SEDVSREGEX" \ | |
-e "s/\(Mark\) $SEDVSREGEX" -e "s/\(Luke\) $SEDVSREGEX" \ | |
-e "s/\(John\) $SEDVSREGEX" -e "s/\(Acts\) $SEDVSREGEX" \ | |
-e "s/\(Romans\) $SEDVSREGEX" -e "s/\(Galatians\) $SEDVSREGEX" \ | |
-e "s/\(Ephesians\) $SEDVSREGEX" -e "s/\(Philippians\) $SEDVSREGEX" \ | |
-e "s/\(Colossians\) $SEDVSREGEX" -e "s/\(Titus\) $SEDVSREGEX" \ | |
-e "s/\(Philemon\) $SEDVSREGEX" -e "s/\(Hebrews\) $SEDVSREGEX" \ | |
-e "s/\(James\) $SEDVSREGEX" -e "s/\(Jude\) $SEDVSREGEX" \ | |
-e "s/\(Revelation\) $SEDVSREGEX" \ | |
-e "s/\([123] [JPTCSKjptcsk][a-z]*\) $SEDCPREGEX" \ | |
-e "s/[Ff]irst \([JPTCSKjptcsk][a-z]*\) \([0-9]*\)\([ ,;.]\)/\[\[1 \1 \2\]\]/g" \ | |
-e "s/[Ss]econd \([JPTCSKjptcsk][a-z]*\) \([0-9]*\)\([ ,;.]\)/\[\[2 \1 \2\]\]/g" \ | |
-e "s/[Tt]hird \([JPTCSKjptcsk][a-z]*\) \([0-9]*\)\([ ,;.]\)/\[\[3 \1 \2\]\]/g" \ | |
-e "s/\([123]\)[snr][td] \([JPTCSKjptcsk][a-z]*\) \([0-9]*\)\([ ,;.]\)/\[\[\1 \2 \3\]\]/g" \ | |
-e "s/\(Genesis\) $SEDCPREGEX" -e "s/\(Exodus\) $SEDCPREGEX" \ | |
-e "s/\(Leviticus\) $SEDCPREGEX" -e "s/\(Numbers\) $SEDCPREGEX" \ | |
-e "s/\(Deuteronomy\) $SEDCPREGEX" -e "s/\(Joshua\) $SEDCPREGEX" \ | |
-e "s/\(Judges\) $SEDCPREGEX" -e "s/\(Ruth\) $SEDCPREGEX" \ | |
-e "s/\(Ezra\) $SEDCPREGEX" -e "s/\(Nehemiah\) $SEDCPREGEX" \ | |
-e "s/\(Esther\) $SEDCPREGEX" -e "s/\(Job\) $SEDCPREGEX" \ | |
-e "s/\(Psalms*\) $SEDCPREGEX" -e "s/\(Proverbs\) $SEDCPREGEX" \ | |
-e "s/\(Ecclesiastes\) $SEDCPREGEX" -e "s/\(Song of Solomon\) $SEDCPREGEX" \ | |
-e "s/\(Isaiah\) $SEDCPREGEX" -e "s/\(Jeremiah\) $SEDCPREGEX" \ | |
-e "s/\(Lamentations\) $SEDCPREGEX" -e "s/\(Ezekiel\) $SEDCPREGEX" \ | |
-e "s/\(Daniel\) $SEDCPREGEX" -e "s/\(Hosea\) $SEDCPREGEX" \ | |
-e "s/\(Joel\) $SEDCPREGEX" -e "s/\(Amos\) $SEDCPREGEX" \ | |
-e "s/\(Obadiah\) $SEDCPREGEX" -e "s/\(Jonah\) $SEDCPREGEX" \ | |
-e "s/\(Micah\) $SEDCPREGEX" -e "s/\(Nahum\) $SEDCPREGEX" \ | |
-e "s/\(Habakkuk\) $SEDCPREGEX" -e "s/\(Zephaniah\) $SEDCPREGEX" \ | |
-e "s/\(Haggai\) $SEDCPREGEX" -e "s/\(Zechariah\) $SEDCPREGEX" \ | |
-e "s/\(Malachi\) $SEDCPREGEX" -e "s/\(Matthew\) $SEDCPREGEX" \ | |
-e "s/\(Mark\) $SEDCPREGEX" -e "s/\(Luke\) $SEDCPREGEX" \ | |
-e "s/\(John\) $SEDCPREGEX" -e "s/\(Acts\) $SEDCPREGEX" \ | |
-e "s/\(Romans\) $SEDCPREGEX" -e "s/\(Galatians\) $SEDCPREGEX" \ | |
-e "s/\(Ephesians\) $SEDCPREGEX" -e "s/\(Philippians\) $SEDCPREGEX" \ | |
-e "s/\(Colossians\) $SEDCPREGEX" -e "s/\(Titus\) $SEDCPREGEX" \ | |
-e "s/\(Philemon\) $SEDCPREGEX" -e "s/\(Hebrews\) $SEDCPREGEX" \ | |
-e "s/\(James\) $SEDCPREGEX" -e "s/\(Jude\) $SEDCPREGEX" \ | |
-e "s/\(Revelation\) $SEDCPREGEX" \ | |
$x | |
done | |
exit 0 |
I changed the latest version (revision 6) to only reference */*.md
which should make it more usable for others.
I just added support for references like "First John 3:2" or "2nd Samuel 3" to support my speech to text engine which isn't consistent.
Added support for entries like "first chronicles" which were not working previously. Also added a USER CONFIG section to make it easier to define the path to your vault and the search path for Markdown files.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That could depend on how you have your vault folder structure. "PATHTOYOURVAULT" above should go to the root of your vault and then the script assumes 1 layer of directories and markdown folders below that. For example, at the root of my vault I have:
Below each of those I have my markdown files. You might need to modify that line if your markdown files are in a different location.
Note that the
[na]
part means that it will only look at directories starting with ana
orn
-- in my case I only want to run this in mynotes
andarchives
directories. You probably will need to change that based on your directory names.