I have a shell script that creates a function (in a bashscript file which is sourced by .bashrc) for each Markdown files to open it in the editor.
Example:
ls /home/nikhil/Notes/Studies
Physics.md
Chemistry.md
Studies.md
index.md
ls /home/nikhil/Notes/Sports
Football.md
Cricket.md
index.md
As you can see, some folder (such as Studies) contains a file with the same name (Studies.md) and index.md, while others (like Sports) contain index.md but not Sports.md
Now, my bashscript creates following functions
oPhysics(){ ${Editor:-vim} /home/nikhil/Notes/Studies/Physics.md }
oChemistry(){ ${Editor:-vim} /home/nikhil/Notes/Studies/Chemistry.md }
oStudies(){ ${Editor:-vim} /home/nikhil/Notes/Studies/Studies.md }
oiStudies(){ ${Editor:-vim} /home/nikhil/Notes/Studies/index.md }
oFootball(){ ${Editor:-vim} /home/nikhil/Notes/Sports/Football.md}
oCricket(){ ${Editor:-vim} /home/nikhil/Notes/Sports/Cricket.md}
oiSports(){ ${Editor:-vim} /home/nikhil/Notes/Sports/index.md}
Notice that: oStudies and oiStudies exist, while only oiSports exists.
Application
Now, as a user, I would like to type oStudies or oSports (this would fail) and not oiSports, and it should automatically run oiSports when oSports function does not exists. This is because, most of the time the user is interested in opening the normal markdown files, and only when they don't exist the user would like to open index.md. The user does not remembers for which folder only index.md exists (for example Sports folder).
How can I do this? The pattern I am looking for is to run a function oiBlahBlah if oBlahBlah does not exists, given that oBlahBlah is invoked by the user.
Replies to suggestions
Making alias won't work as I don't want oStudies to execute oiStudies