Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting "grep searching error" for all page #1

Open
dnordgren opened this issue Apr 5, 2021 · 5 comments
Open

Getting "grep searching error" for all page #1

dnordgren opened this issue Apr 5, 2021 · 5 comments

Comments

@dnordgren
Copy link

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:

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

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:

(when (string-prefix-p "grep" result)

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

@llcc
Copy link
Owner

llcc commented Apr 7, 2021

@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
Copy link
Author

dnordgren commented Apr 7, 2021

I think I've found it!

I've changed these lines:

org-logseq/org-logseq.el

Lines 82 to 83 in feba4fd

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

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
Copy link
Owner

llcc commented Apr 7, 2021

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
Copy link
Owner

llcc commented Apr 7, 2021

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

org-logseq/org-logseq.el

Lines 83 to 86 in b5cdf8b

(format (pcase type
('page "grep -niR \"^#+\\(TITLE\\|ALIAS\\): *%s\" %s --exclude-dir=.git" )
('id "grep -niR \":id: *%s\" %s --exclude-dir=.git"))
query (shell-quote-argument org-logseq-dir))))

@lyserenity
Copy link

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

org-logseq/org-logseq.el

Lines 83 to 86 in b5cdf8b

(format (pcase type
('page "grep -niR \"^#+\\(TITLE\\|ALIAS\\): *%s\" %s --exclude-dir=.git" )
('id "grep -niR \":id: *%s\" %s --exclude-dir=.git"))
query (shell-quote-argument org-logseq-dir))))

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants