zx
zx copied to clipboard
Feature request: automatically add a newline after commands that don't end their output with one
Hello. I'd love it if there was an option to ensure the output printed in the terminal from commands executed have a newline automatically added if the output didn't end with one.
Basically I have this:
const commitMessageSummary = (
await $`git log -1 --pretty=format:%s`
).toString();
console.log({ commitMessageSummary });
Expected Behavior
I would like the output to be this:
$ git log -1 --pretty=format:%s
Release 8.0.1
{ commitMessageSummary: 'Release 8.0.1' }
Actual Behavior
This is the actual output:
$ git log -1 --pretty=format:%s
Release 8.0.1{ commitMessageSummary: 'Release 8.0.1' }
Workaround
const commit_message_summary = (
await $`git log -1 --pretty=format:%s`
).toString();
console.log(); // Fix newline not added from the previous command
console.log({ commit_message_summary });
Right now I have a ton of these scattered in my scripts:
console.log(); // Fix newline not added from the previous command
I think this is something that zx could probably handle automatically.
Specifications
- Version: 8.0.1
- Platform: macOS 14.4.1
As zsh does 👌🏻
Hi, @antonmedv. Can I implement this?
@stefansundin I think this issue has been fixed. How did you get Release 8.0.1 as output?
I used the same code
import { $ } from "zx";
const commitMessageSummary = (
await $`git log -1 --pretty=format:%s`
).toString();
console.log({ commitMessageSummary });
Output:
if this issue still exists. I would like to have more context.
@Anonymous961 You need to turn on verbose mode in v8 and later.
$.verbose = true;
Doing so causes zx to automatically print all the $ shell commands, and their output. Kinda like setting set -x in bash. It used to be the default before v8.