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
351 stars 11 forks source link

Bash etc: Newline characters that come from variable values disappear #109

Closed Taitava closed 2 years ago

Taitava commented 2 years ago

Example:

  1. Copy all of the text from this issue to the clipboard, including newlines in between paragraphs.
  2. Execute a shell command like echo {{clipboard}}, make sure the output is either a notification balloon, or current file.

On Windows PowerShell, the test works ok, the newline characters are preserved in the output. But on Bash and Zsh (latter tested by @FelipeRearden on Mac, I tested Bash on Linux), the newline characters disappear.

I think it happens because these Bourne family shells consider an escaped newline to mean something like "continue this command in the next line", i.e. just ignore the newline character, pretend it never existed. This is just my guessing, and I can't say for certain that this is how these shells really think.

I need to make the escaping system to do the following:

Edit: Actually, it seems that I need to double the escape character, so \n will become \\n. Otherwise echo -e on Bash will output a literal n instead of a newline.

Taitava commented 2 years ago

Fixed. I'll release a beta4 soon.

FelipeRearden commented 2 years ago

AMAZING!!!!!!!!!

Taitava commented 2 years ago

beta4 is now released: https://github.com/Taitava/obsidian-shellcommands/releases/tag/0.7.0-beta4

@FelipeRearden can you confirm here that newlines work now? Just one thing that I've learned about the echo command on Bash: I needed to add an -e parameter to the command, otherwise newlines appear as \n in the output. So a complete example command: echo -e {{clipboard}}, and another: echo -e {{selection}}.

As you have Zsh instead of Bash, I do not know if your echo works differently.

FelipeRearden commented 2 years ago

beta4 is now released: https://github.com/Taitava/obsidian-shellcommands/releases/tag/0.7.0-beta4

Thank you very much @Taitava !!!! :)

@FelipeRearden can you confirm here that newlines work now? Just one thing that I've learned about the echo command on Bash: I needed to add an -e parameter to the command, otherwise newlines appear as \n in the output. So a complete example command: echo -e {{clipboard}}, and another: echo -e {{selection}}.

Sure @Taitava !!! I will test and get back to you.

I have some chores and errands to do today but tomorrow morning I will concentrate in testing beta 4 :)

As you have Zsh instead of Bash, I do not know if your echo works differently.

I'm gonna test echo , echo -e and printf too. Thanks for the tip :)

Question for @Taitava about testing beta 4

Should I test everything ({{path_}}) or focus only on {{clipboard}} and {{selection}} ?

Should I take a look at data_backup.json or not?

Thanks!!!!!

Taitava commented 2 years ago

I have some chores and errands to do today but tomorrow morning I will concentrate in testing beta 4 :)

  • Sorry for not testing beta 4 now :)

Take your time! πŸ™‚ I don't have any time expectations. Even if I sometimes happen to do stuff fast and post a lot, I don't expect others to react immediately πŸ™‚. I can wait. We all have our timetables.

As you have Zsh instead of Bash, I do not know if your echo works differently.

I'm gonna test echo , echo -e and printf too. Thanks for the tip :)

Good ideas!

Question for @Taitava about testing beta 4

Should I test everything ({{path_}}) or focus only on {{clipboard}} and {{selection}} ?

Should I take a look at data_backup.json or not?

Thanks!!!!!

If it's not too much work, you could test all your variable tests just in case, although {{clipboard}} and {{selection}} are the most important. No need to test backup files, I believe it works solidly now.

Thank you a lot! You are helping a lot! 😎

FelipeRearden commented 2 years ago

Take your time! πŸ™‚ I don't have any time expectations. Even if I sometimes happen to do stuff fast and post a lot, I don't expect others to react immediately πŸ™‚. I can wait. We all have our timetables

Thanks @Taitava !! For SC I always want to concentrate 100% when testing because I know that we need to be very calm to don't make a mistake and prepare a good explanation if I find something that I judge as wrong ;)

If it's not too much work, you could test all your variable tests just in case, although {{clipboard}} and {{selection}} are the most important. No need to test backup files, I believe it works solidly now.

No problem at all @Taitava !!! I go for full test tomorrow:)

Thanks we talk tomorrow!!!!!!!

Taitava commented 2 years ago

Take your time! πŸ™‚ I don't have any time expectations. Even if I sometimes happen to do stuff fast and post a lot, I don't expect others to react immediately πŸ™‚. I can wait. We all have our timetables

Thanks @Taitava !! For SC I always want to concentrate 100% when testing because I know that we need to be very calm to don't make a mistake and prepare a good explanation if I find something that I judge as wrong ;)

That's also true! "Postponing" something for a bit later, peaceful time, can be more respectful than trying to do something quickly and in a hurry. Waiting is not always a bad thing. πŸ™‚

If it's not too much work, you could test all your variable tests just in case, although {{clipboard}} and {{selection}} are the most important. No need to test backup files, I believe it works solidly now.

No problem at all @Taitava !!! I go for full test tomorrow:)

Thanks we talk tomorrow!!!!!!!

Thank you! 🌞

FelipeRearden commented 2 years ago

Working perfect on version 0.7.0-beta4 Obsidian 0.12.19

More details about the test here in #96

Thank you very much for this fix @Taitava !!!!!!!

Taitava commented 2 years ago

Really nice to know! πŸ™‚