obsidian-execute-code icon indicating copy to clipboard operation
obsidian-execute-code copied to clipboard

[FR] `console` codeblocks

Open chlohal opened this issue 3 years ago • 3 comments

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 avatar Jan 20 '23 17:01 chlohal

This would pair well with #129

chlohal avatar Jan 20 '23 17:01 chlohal

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'

twibiral avatar Feb 23 '23 20:02 twibiral

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.

mayurankv avatar Jun 05 '23 20:06 mayurankv