Yakitrak / obsidian-cli

Interact with Obsidian in the terminal. Open, search, create, update, move and delete notes!
https://yakitrak.github.io/obsidian-cli-docs
MIT License
388 stars 15 forks source link

`open` fails to open note with URL-encoding #36

Open danielwerg opened 2 months ago

danielwerg commented 2 months ago

Describe the bug

open doesn't decodes URL-encoding

To Reproduce

Steps to reproduce the behaviour:

  1. Create note with space or/and emoji in title
  2. obsidian-cli open "obsidian://open?vault=obsidian&file=note%20with%20space"
  3. File “note%20with%20space” not found.

Expected behaviour

Decode URL and open note

Workarounds

  1. obsidian-cli open "$(encoded_string="obsidian://open?vault=obsidian&file=note%20with%20space"; printf "%b\n" "${encoded_string//\%/\\x}")"
  2. xdg-open "obsidian://open?vault=obsidian&file=note%20with%20space"
  3. obsidian-cli open "$(node -e "console.log(new URL(process.argv[1]).searchParams.get('file'))" "obsidian://open?vault=obsidian&file=note%20with%20space")"
  4. obsidian-cli open "$(trurl "obsidian://open?vault=obsidian&file=note%20with%20space" -g '{query:file}' )"
  5. obsidian-cli open "$(perl -mURI -E 'say URI->new(@ARGV[0])->query_param(file)' -- "obsidian://open?vault=obsidian&file=note%20with%20space")"
Yakitrak commented 2 months ago

Hi, thanks for the feedback again. Adding encoding should be straightforward and I can add it soon. Also just to confirm, Is your note called "obsidian://open?vault=obsidian&file=note%20with%20space" or is that a mistake on the description?

obsidian-cli open "obsidian://open?vault=obsidian&file=note%20with%20space"

danielwerg commented 2 months ago

Note called note with space, when you Copy Obsidian URL inside obsidian obsidian://open?vault=VAULT&file=note%20with%20space is copied, after note title is run through encodeURI.

Yakitrak commented 2 months ago

But you would call the obsidian-cli open "note with space" or with encoding it will be obsidian cli open "note%20with%20space". The former functionality works as expected, and the latter I can add to the tool, although I didn't think there would be a need for it originally.

What I am trying to say is in your example you used obsidian-cli open "obsidian://open?vault=obsidian&file=note%20with%20space" which is using the entire url in the open command which is not correct usage of the tool.

danielwerg commented 2 months ago

Oh, I didn't even tested without encoding. I just assumed it would support Obsidian URIs. Added couple more workaround that can parse URI and feed it to obsidian-cli.

Yakitrak commented 2 months ago

It uses Obsidian URIs in the background, but it doesn't use them as arguments. If you want to use the URI, you can use it directly without using the CLI. e.g. on Mac it would be open "obsidian://open?vault=obsidian&file=note%20with%20space"