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.
The text was updated successfully, but these errors were encountered:
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
Let's say you have a file
MyNote.mdin the root of your vault, and it's currently open in Obsidian. Then you have a shell command likeecho "{{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 docd {{folder_path:relative}}=cd /, it will go to filesystem root, e.g. toC:\. Combine/to a subfolder on Windows, like this:cd {{folder_path:relative}}SubFolderName=cd /SubFolderNameresults in Windows not finding the specified path, even ifSubFolderNamewould 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. Imaginecd. 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,cdwithout 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.SubFolderNameinstead ofSubFolderName//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.The text was updated successfully, but these errors were encountered: