Taitava / obsidian-shellcommands

Execute system commands via hotkeys or command palette in Obsidian (https://obsidian.md). Some automated events are also supported, and execution via URI links.
GNU General Public License v3.0
360 stars 11 forks source link

Change {{folder_name}} and {{event_folder_name}} to return a dot instead of an empty string when folder is vault root #304

Closed Taitava closed 1 year ago

Taitava commented 1 year ago

Discussed in https://github.com/Taitava/obsidian-shellcommands/discussions/237

Originally posted by **Taitava** July 16, 2022 Currently, if a note is located in the vault's root folder, and a shell command like `echo {{folder_name}}` is executed, then the value of `{{folder_name}}` is an empty text. **I'm planning to change the value to be a dot `.` when the folder in question is the vault's root folder.** This is a breaking change, unfortunately. (If the folder is not the vault's root, then nothing will change). Examples of situations that are currently problematic: | Example situation | Current, problematic result | Better result after the change | | ------------------ | ---------------------------- | ----------------------------- | | When defining a file path where `{{folder_name}}` is just one part of it, e.g. `echo "Content" > {{folder_name}}/NewNote.md` | `echo "Content" > /NewNote.md`
Creates a file to the file system root, outside of the Obsidian vault. | `echo "Content" > ./NewNote.md`
Creates a file correctly in the current working directory, i.e. usually the vault's root folder. | When copying a directory, e.g. `cp -r {{folder_name}} /absolute/path/for/new/folder/outside/of/the/vault` | `cp -r /absolute/path/for/new/folder/outside/of/the/vault`
The first argument to `cp` is omitted because it was empty. | `cp -r . /absolute/path/for/new/folder/outside/of/the/vault`
The first argument is correctly `.` so it's not accidentally omitted. ## Variables affected by the change - `{{folder_name}}` - `{{event_folder_name}}` ## Variables that already give a dot `.` in similar situations - `{{folder_path:relative}}` - `{{event_folder_path:relative}}` - `{{new_note_folder_name}}` - `{{new_note_folder_path}}` As there are already variables that give a dot `.` for the root folder, this change will streamline the behavior.
Taitava commented 1 year ago

Done. Will be released in 0.18.0.

Taitava commented 1 year ago

Released.