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

Variable {{folder_path:relative}} returns / when current file is in vault root #52

Closed
Taitava opened this issue Sep 28, 2021 · 2 comments
Closed

Comments

@Taitava
Copy link
Owner

@Taitava Taitava commented Sep 28, 2021

Let's say you have a file MyNote.md in the root of your vault, and it's currently open in Obsidian. Then you have a shell command like echo "{{folder_path:relative}}".

Currently the result is quite bad: / . On Mac and Linux it refers to the filesystem root. On Windows, well... it depends. If you happen to do cd {{folder_path:relative}} = cd /, it will go to filesystem root, e.g. to C:\. Combine / to a subfolder on Windows, like this: cd {{folder_path:relative}}SubFolderName = cd /SubFolderName results in Windows not finding the specified path, even if SubFolderName would be an existing folder.

This comes from Obsidian's API, although there isn't actual documentation describing this behavior. A vault's root folder has a relative path of /. No pun intended when mentioning this, I'm mentioning the source of the value in order to figure out a possible solution: should Obsidian fix it, or should this plugin change the value.

I have been thinking about the folowing values that {{folder_path:relative}} could return when the current file resides in the vault's root directory:

  • (that's an empty string)
  • ./ (on Linux and Mac), .\ (on Windows)
  • .

The meaning for all of these is the same. All of these mean this, current directory. In the context of this plugin, relative paths are meant to be relative to the vault's root folder. If we want to know a relative path from the vault's root folder to the vault's root folder, then either of these are correct answers - at least in theory.

I will rule them out one by one:

  • is terrible. Imagine cd . On Windows it's not that bad, it stays in the current directory, which happened to be already the vault's root, so that's ok. On linux, cd without an actual parameter goes to the user's home directory. So this would be a wrong solution to this issue.
  • .//.\ is kind of correct, but it's inconsistent. When you have a file in a subfolder in a vault, {{folder_path:relative}} gives a folder name without a trailing slash, e.g. SubFolderName instead of SubFolderName//SubFolderName\. To be consistent, also the vault's root folder should not have a trailing slash.
  • . it is, period. I wanted to write down the reasons why I think . is the best solution to this issue, and the reasons are written above.
@Taitava Taitava added the bug label Sep 28, 2021
@Taitava Taitava added this to the 0.4.1 milestone Sep 28, 2021
@Taitava Taitava changed the title {{folder_path:relative}} returns / when current file is in vault root Variable {{folder_path:relative}} returns / when current file is in vault root Sep 28, 2021
@Taitava
Copy link
Owner Author

@Taitava Taitava commented Sep 28, 2021

@Taitava Taitava added this to Short term, planning in Roadmap Sep 28, 2021
@Taitava
Copy link
Owner Author

@Taitava Taitava commented Sep 28, 2021

Should be fixed, will be released in 0.4.1.

@Taitava Taitava moved this from Short term, planning to Actively working on in Roadmap Sep 28, 2021
Taitava added a commit that referenced this issue Sep 29, 2021
@Taitava Taitava moved this from Actively working on to Released in Roadmap Sep 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Roadmap
Released lately
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant