Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stefansundin opened this issue Apr 13, 2024 · 4 comments
Labels
feature New feature or request

Comments

@stefansundin
Copy link

stefansundin commented Apr 13, 2024

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:

$.verbose = true;

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

$.verbose = true;

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
@antonmedv antonmedv added the feature New feature or request label Apr 13, 2024
@antonmedv
Copy link
Collaborator

As zsh does 👌🏻

@mgrithm
Copy link

mgrithm commented Apr 19, 2024

Hi, @antonmedv. Can I implement this?

@Anonymous961
Copy link

Anonymous961 commented May 16, 2024

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

@stefansundin
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants