shuckster / denote-md

Shell script for Denote's Markdown + YAML variant
GNU General Public License v3.0
5 stars 1 forks source link

Hello, #1

Open snuffop opened 2 months ago

snuffop commented 2 months ago

I, like you love the simplicity idea that Prot has come up with for the file naming. I was a long-time user of Space macs and Doom, but, cannot get past the BLOAT of that system.
I use Neovim. No Flame war intentions.

I'm also using your denote-md and vim-denote-md with ZK.
I'm looking for your input on the best way to set a hook in your script, where when a file operation is done on the file system I can trigger the zk index process. Thus cleaning up the telescope searches and the like. I was thinking of setting some variable in each function where it makes sense, and after main the shell could test for the variable existence and thus run the zk index.

What do you think?

shuckster commented 2 months ago

Thanks for dropping by, and I'm glad this implementation of Prot's idea has been useful to you.

If I were to implement a hook, I think the following might be the way I would approach it:

Have the script check for the availability of a function, perhaps specified by a new environment variable, and run it after each file operation. I could imagine the denote-md script calling the function with an argument specifying the kind of operation that was just run, so we could conditionally perform actions rather than doing something on every change.

Thinking about it, it wouldn't have to be a function only. The environment variable could just hold some arbitrary command.

What do you think?

shuckster commented 2 months ago

Not sure why I didn't think of this the first time around, but does entr cover your use-case?

snuffop commented 1 month ago

Hi again, yes entr would work, and the case use in my mind would be bufclose or more along the autocmd method for a specific filetype setup inside Nvim. I believe you have me pointed in the right direction with your first suggestion, as I would only want this run on files from within the zk notebook dir and markdown.

I'm also thinking adding additional regex to account for text markdown style links.

shuckster commented 1 week ago

Just wanted to pop back and say that I've not forgotten about this, as I would like a way to auto-commit my updated notes, and it feels like a hook would be a natural way to do that without needing something external like watchman or entr.

What do you mean about the RegExp Markdown links please? I'm not sure I understood that one.

snuffop commented 4 days ago

I modified the handle_list_backlinks with

handle_list_backlinks() {
    if test "$1" = ""; then
        handle_help "list backlinks"
        return
    fi
    local input_file="$1"
    local identifier=$(identifier_from_filename "$input_file")
    local search_pattern="[[denote:$identifier]]"
    local markdown_search_pattern="\[.+\]\(denote:([0-9]+T[0-9]+)\)"
    # Use grep to search all markdown files for the pattern, excluding the input file
    grep -lF "$search_pattern" ${DENOTE_MD_NOTES_PATH}*.md |
        grep -v "$identifier" |
        while read -r file; do
            print_note_name "$file"
        done
    pcregrep -o1 "$markdown_search_pattern" ${DENOTE_MD_NOTES_PATH}*.md |
        grep "$identifier" | cut -d: -f1 |
        while read -r file; do
            print_note_name "$file"
        done
}
snuffop commented 4 days ago

This way I have the script returning

[[denote:20241121T000000]]

or

[link text](denote:20241121T000000)

as valid backlinks

I'm thinking I need to add

[[denote:20241121T000000][Link Text]]

as well to manage org-mode style links as well