zx icon indicating copy to clipboard operation
zx copied to clipboard

Feature request: automatically add a newline after commands that don't end their output with one

Open stefansundin opened this issue 1 year ago • 2 comments

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

stefansundin avatar Apr 13 '24 00:04 stefansundin

As zsh does 👌🏻

antonmedv avatar Apr 13 '24 16:04 antonmedv

Hi, @antonmedv. Can I implement this?

mvares avatar Apr 19 '24 13:04 mvares

@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: image

if this issue still exists. I would like to have more context.

Anonymous961 avatar May 16 '24 04:05 Anonymous961

@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.

stefansundin avatar May 16 '24 04:05 stefansundin