Create tag collections for your Markdown library

Maybe you are like me and maintain all your notes in a folder with thousands of Markdown files in it.

You might not want to always search afresh for all those documents that have the tag "product" you have created.

Let's say your root folder is called "Notes", then you create a .script folder within in (that makes its location Notes/.script).

Create the following script as and make it executable with chmod u+x You can now create tag collections with the command ./ TAG and it will be saved in your inbox (which is hard-coded for now, feel free to change the folder location).


# Check if a TAG argument was provided
if [ -z "$1" ]; then
  echo "Error: TAG argument is required."
  exit 1


# Get current timestamp in the desired format
TIMESTAMP=$(date +'%y%m%d%H%M')

# Run the ag and awk commands, substituting the TAG and TIMESTAMP variables
cd ..
ag "#$TAG" --markdown | awk -F'|' -v ts=$TIMESTAMP -v tag=$TAG '{sub(":.*", "", $NF); sub(".md", "", $NF); printf "- [[%s]]\n", $NF}' > "_Inbox/${TIMESTAMP}-collection-${TAG}.md"
Did this help you?