org-logseq icon indicating copy to clipboard operation
org-logseq copied to clipboard

Getting "grep searching error" for all page

Open dnordgren opened this issue 3 years ago • 5 comments

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

  • Install via Straight
  • Set org-logseq-dir variable (which I've verified to be correct via Emacs variable explorer C-h v)
  • Execute M-x org-logseq-mode in the current buffer

Environment info:

  • Emacs version 27.1
  • grep version: grep (GNU grep) 3.6 Packaged by Homebrew
  • I'm on macOS

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.

dnordgren avatar Apr 05 '21 11:04 dnordgren

@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.

llcc avatar Apr 07 '21 12:04 llcc

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!

dnordgren avatar Apr 07 '21 19:04 dnordgren

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 avatar Apr 07 '21 21:04 llcc

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

llcc avatar Apr 07 '21 22:04 llcc

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)).

lyserenity avatar Jan 25 '22 13:01 lyserenity