twibiral / obsidian-execute-code

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

[FR] `console` codeblocks #213

Open chlohal opened 1 year ago

chlohal commented 1 year ago

On GitHub and many other services, you can use a code-block with the console language to represent a console session. For example:

chlohal@DESKTOP2FA3C:~$ echo 'hi'

It would be a great quality-of-life feature if we could

  1. Parse console blocks
  2. Recognize command lines (with a $)
  3. When running the block, execute the command in the proper directory.

This may have security concerns, but IMO the ease-of-use provided is justifiable. Someone could easily cd in a bash block, but this is easier to write and scans better.

chlohal commented 1 year ago

This would pair well with #129

twibiral commented 1 year ago

That's an interesting idea! How do we handle it if the username given is different from the username of the current user?

What happens if I use different paths (or users) in different lines without explicitly changing the directory? Like this:

user1@DESKTOP:~$ echo 'hi'
user1@DESKTOP:~/documents$ echo 'hi'
user2@DESKTOP:~/documents$ echo 'hi'
mayurankv commented 1 year ago

One option would be to cd to the directory before every line. Or alternatively, only look at the first line for the directory and ignore any subsequent changes.

For username I would suggest ignoring this. It's not as if you could (or rather should) run it as a different user so presume that it is added markup for display purposes that can be ignored.