Skip to content

noteSearch

holzkohlengrill edited this page Dec 15, 2023 · 2 revisions

Notes search

You took a ton of notes and you want to find something very quickly. This function(s) provides you a list with the results + surrounding lines to keep track of the context you searched for.

We assume to have a folder structure like:

$ tree /meeting/notes
/meeting/notes
├── meeting-notes-2017.md
├── meeting-notes-2018.md
└── meeting-notes.md

Copy the function(s) into your ~/.bashrc file and source them (source ~/.bashrc).

meetingNotesPath='/meeting/notes'
mSearch() {
        # Search for current meeting-notes (meeting-notes.md)
        # All arguments are optional
        # Arg1: keyword to search for
        # Arg2: Surrounding lines of matches
        
        numPadLines=7
        # "${2-${numPadLines}} ---> Use numPadLines if 2nd argument is unset
        
        tac "${meetingNotesPath}/meeting-notes-${3-2018}.md" | grep -nC "${2-${numPadLines}}" -i "$1" --color=auto --group-separator=***********************************************************
        printf "\n---\n\n++++++++++ Info: Text reversed (read: bottom > top) ++++++++++\n"
}

mSearchOld() {
        # Search for older meeting-notes (meeting-notes-<year>.md)
        # All arguments are optional
        # Arg1: keyword to search for
        # Arg2: Surrounding lines of matches
        # Arg3: Use notes for year yyyy

        numPadLines=7
        
        tac "${meetingNotesPath}/meeting-notes-${3-2018}.md" | grep -nC "${2-${numPadLines}}" -i "$1" --color=auto --group-separator=***********************************************************
        printf "\n---\n\n++++++++++ Info: Text reversed (read: bottom > top) ++++++++++\n"
}
Clone this wiki locally