twibiral / obsidian-execute-code

Obsidian Plugin to execute code in a note.
MIT License
1.06k stars 67 forks source link

How to set current path #287

Open JCzz opened 1 year ago

JCzz commented 1 year ago

Hi

How can 'i set the current path for a shell or any language?

I would like to execute in the same directory as the Obsidian node.md file.

GitTom commented 11 months ago

Agreed.

My 'shell' code block created a file, and I assumed the file would be in the same directory as the Obsidian note, but instead it is written to /Users/[user]/AppData/Local/Obsidian.

GitTom commented 11 months ago

Here's an interim solution...
Use a {pre} block, or maybe the 'inject code' setting, to set the cwd... (remember that {pre} doesn't work in combination with 'run-')

file_path=@vault_path/@note_path
dir_path=$(dirname "$file_path")
cd $dir_path
pwd