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

jobs can print commands on multiple lines #9808

Closed
pacien opened this issue May 23, 2023 · 3 comments
Closed

jobs can print commands on multiple lines #9808

pacien opened this issue May 23, 2023 · 3 comments

Comments

@pacien
Copy link

pacien commented May 23, 2023

If a command spanning over multiple lines is sent to background, the jobs
command also prints that command over multiple lines in its output. This makes
parsing it harder.

As a consequence, count (jobs) does not return the expected result in that
case. (A workaround is to use count (jobs -g) instead).

For example, this returns a count of 2 instead of 1 job:

> sleep \
    1000 &

> jobs
Job	Group	CPU	State	Command
1	2667403	0%	running	sleep \
1000 &

> count (jobs)
2

It could be nicer to force the content of the "Command" field to stay on one
line.

Fish version 3.6.1 on Linux (NixOS).

@zanchey zanchey added this to the fish-future milestone May 23, 2023
@elyashiv
Copy link
Contributor

elyashiv commented Jul 3, 2023

Hi,

I started looking into implementing this, and there are a few things that are needed to be considered, and I would like to hear other poeple opinios on them.

  1. Should this be the deffault behaviour or behind a flag?
  2. What to print if the the command is multiline? one option is to just trim (with an elipsis?) another is to replace the new lines with some other string (space? a literal \n?)
  3. Another option to "fix" this is to get a more pipe friendly output - an array or a null delimited list of the jobs (like find -print0). What do you think of that?

@faho
Copy link
Member

faho commented Jul 3, 2023

Should this be the deffault behaviour or behind a flag?

The default behavior shouldn't break like this so not a flag.

In general we try to make the default behavior good, adding flags is extremely tempting if you don't want to decide, but makes for a poor experience.

another is to replace the new lines with some other string (space? a literal \n?)

If we were to replace, we would escape it like string escape does. I.e. it would use the escape_string() function, so it's like other places where we incorporate arbitrary fish script.

an array or a null delimited list of the jobs (like find -print0)

I don't believe this specific thing is all that useful to pipe so I don't think this is needed. For the most part you'll see count like that.

Escaping is fine.

@elyashiv elyashiv mentioned this issue Jul 5, 2023
3 tasks
@elyashiv
Copy link
Contributor

elyashiv commented Jul 9, 2023

There are a few other placces that print a command string to the user.

Some that I found:

  • disown.cpp
  • fish_job_summary.fish
  • proc.cpp (print_exit_for_jobs)

As they are not suppose to be parsed by a script, I'm not sure we want to escape them.

@faho faho closed this as completed Jul 10, 2023
@zanchey zanchey modified the milestones: fish-future, fish 3.7.0 Jul 11, 2023
@zanchey zanchey modified the milestones: fish next-3.x, fish 3.7.0 Dec 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants