Hello friends!
First Showcase from me!
Use case
Ever encountered the problem of having 8-15 tabs of related content open – you can even save those as a Workspace and come back to it, right – and forgot which file was recently added to – where you would you like to go back to and refer to it…or build on it…
Sure, the Remember Cursor Position plugin can be helpful but you may have already moved in that file since and the position of the cursor was saved again…and you don’t remember which file it was or what it really was…
I tried looking for a solution on the forum and instead solved it for myself with some bot help…
It is somewhat rudimentary but can be helpful in itself.
Templater snippet
<%*
// Get the active workspace
const workspace = app.workspace;
// Get all open leaves (tabs)
const leaves = workspace.getLeavesOfType("markdown");
// Define the list of filenames to exclude
const excludeFilenames = [
"FileModifiedFileList_Query",
"fifty latest notes",
"quicksearch"
];
// Extract filenames, filter out excluded filenames
const filenames = leaves
.map(leaf => leaf.view.file.basename)
.filter(filename => !excludeFilenames.includes(filename));
// Format the filenames for search modal
let formatted = `file: /^(${filenames.join("|")})\\.md/`;
// Copy the result to the clipboard
navigator.clipboard.writeText(formatted).then(() => {
// Show a notice to the user
new Notice(`Copied to clipboard:\n${formatted}`);
}).catch(err => {
console.error('Could not copy text: ', err);
});
_%>
Save the snippet to any name, register it in Templater so you can add a hotkey to it.
Because all open tabs mean all open markdown files in any tab groups and sidebar areas, add any of your md files pinned to any sidebars in the // Define the list of filenames to exclude
section of the script.
I added three, as you can see. Those will be excluded for me.
Usage
While having any note open, activate the Templater script (with a hotkey, if you have bound one).
All filenames except for those excluded in the array are added to the clipboard in the following format:
E.g.:
file: /^(@AddamsB1995|Culinary Habits|Kitchen Etiquette)\.md/
- Explanation of what’s here: this is a regular expression format query for files populated one after the other where the
|
basically meansOR
, meaning all of the items will be valid parent files to search in. We wrapped the items in brackets. The^
and\.md
parts had to be added to get the exact filenames and none other.
Paste what’s on the clipboard into the search modal bar and type in your query.
E.g.:
file: /^(@AddamsB1995|Culinary Habits|Kitchen Etiquette)\.md/ utensils
You can type in a regex search after the pasted bit:
file: /^(@AddamsB1995|Culinary Habits|Kitchen Etiquette)\.md/ /<regular expression here>/
- For example:
file: /^(@AddamsB1995|Culinary Habits|Kitchen Etiquette)\.md/ /cut.*?cucumber/
.*?
means any characters between the word stemcut
andcucumber
, including zero characters- the ending
/
at the end of your query is optional
Hopefully, you’ll find what you’ve been looking for!
Plus
This can also be used for finding common themes among your Zotero-imported annotation files and any randomly opened or carefully selected files which already have some (rather long) content.
Possible upgrades
If anyone would like to build on it, they can add some user input bit for what would be the search term pasted to the end of what we’ve got now.
Then you can also activate the search modal pane so all the query will show up there without having to paste anything in.
See ver. 2 below with these upgrades.
A further upgrade would be reading the content of all open markdown files and find common themes based on some patterns.