llcc / org-logseq

Org-logseq allows you to open logseq-style page and block link along with Org Mode.
100 stars 8 forks source link

Getting "grep searching error" for all page #1

Open dnordgren opened 3 years ago

dnordgren commented 3 years ago

Summary

Hi! Found this via the https://github.com/logseq/awesome-logseq -- the functionality seems like it'd be great, thanks for building this! However, after setting it up, I'm having some issues:

When using C-c C-o on a page or ID link, clicking the link in the Emacs UI or using M-x org-logseq-open-link I'm getting grep searching error.

My Steps

Environment info:

Error

grep searching error in status bar.

Debugging

I see the page query here: https://github.com/llcc/org-logseq/blob/feba4fdfccc37ae49e7ab085cf58bb20a65ee680/org-logseq.el#L82

If I run the following grep command from my org-logseq-dir in zsh

grep -niR "^#+\\(TITLE\\): *Apr 4th, 2021" --exclude-dir=".git"

(manually created based on that query), I'm seeing the grep result:

journals/2021_04_04.org:1:#+TITLE: Apr 4th, 2021

So it seems like the base grep query works. However, when I add in the "%s" part of the query, it causes grep: Apr 4th, 2021: No such file or directory, which looks like it could be triggering the error line I'm seeing: https://github.com/llcc/org-logseq/blob/feba4fdfccc37ae49e7ab085cf58bb20a65ee680/org-logseq.el#L105

Why is that extra part of the query necessary? Apologies, as I'm not too experienced with grep.

llcc commented 3 years ago

@dnordgren Thanks for using org-logseq. Could you please check the result of the following cmd? Please replace your logseq dir to your real logseq path.

when I add in the "%s" part of the query,

Do you mean the same thing as below?

grep -niR "^#+\\(TITLE\\): *Apr 4th, 2021" "your logseq dir" --exclude-dir=".git"

There might be some unexpected behaviors on MacOS compared to other systems. I don't have one, so I cannot check it for you.

dnordgren commented 3 years ago

I think I've found it!

I've changed these lines: https://github.com/llcc/org-logseq/blob/feba4fdfccc37ae49e7ab085cf58bb20a65ee680/org-logseq.el#L82-L83

to

        ('page "grep -niR \"^#+\\(TITLE\\): *%s\" %s --exclude-dir=.git")
        ('id "grep -niR \":id: *%s\" %s --exclude-dir=.git"))

(removing " around .git and the second %s for grep FILE)

it's working great locally now! Could be macOS specific.

--

This package is great, thank you for your contribution!

llcc commented 3 years ago

Hi @dnordgren, So happy that you solved the problem. Then this should be a space-escape issue. I will fix it in the next version.

But I wonder that space is not permitted in the macOS file path? Since if any space exists in the path, the path should be quoted, or it will be treated as multiple arguments by grep.

llcc commented 3 years ago

This should be fixed by the following code. Could you please give it a try?

https://github.com/llcc/org-logseq/blob/b5cdf8ba6fcb4fddc626475255491accf1867801/org-logseq.el#L83-L86

lyserenity commented 2 years ago

This should be fixed by the following code. Could you please give it a try?

https://github.com/llcc/org-logseq/blob/b5cdf8ba6fcb4fddc626475255491accf1867801/org-logseq.el#L83-L86

I had tested the code on my Mac. And the line 86 would probably be changed to (shell-quote-argument (expand-file-name org-logseq-dir)).