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

Add fish_job_summary, called whenever a job ends, stops, or is signalled #6959

Merged
merged 2 commits into from May 19, 2020
Merged

Add fish_job_summary, called whenever a job ends, stops, or is signalled #6959

merged 2 commits into from May 19, 2020

Conversation

soumya92
Copy link
Contributor

Description

Add fish_job_summary, called whenever a job ends, stops, or is signalled

This allows users to customise the behaviour of the shell by redefining the function. This is similar to how fish_title or fish_greeting behave, where the default implementation can be easily overridden.

The function receives as arguments the job id, command line, signal name and signal description.

Fixes #4319, maybe #1018 and #2727.

TODOs:

  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.md

@ridiculousfish
Copy link
Member

Do not worry about the CI failure, there is one flaky test.

Copy link
Member

@ridiculousfish ridiculousfish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really good idea!

Right now fish has logic to suppress messages for foreground jobs (this lives in job_wants_message), because printing status for foreground jobs would be too noisy. Do we want to invoke fish_job_summary for all jobs and let it filter out foreground ones? Or do we just not invoke it for foreground jobs?

src/proc.cpp Outdated Show resolved Hide resolved
wcstring buffer = wcstring(L"fish_job_summary");
for (const wcstring &arg : args) {
buffer.push_back(L' ');
buffer.append(escape_string(arg, ESCAPE_ALL));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think escaping is not desirable here - the function should receive the actual command that was run. It can be escaped with string escape if the function chooses to (maybe it should).

Copy link
Contributor Author

@soumya92 soumya92 Apr 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is building a single string for execution, so the individual arguments need to be escaped once in order to be split up correctly.

With escaping the execution string will be fish_job_summary 3 sleep\ 10\ \&, which will correctly provide the args "3" and "sleep 10 &". Without escaping the execution string will be fish_job_summary 3 sleep 10 &, which in addition to providing the wrong args "3", "sleep", "10", will also try to background the function call.

You can see from the expect based tests that the special characters are not escaped when the function prints them, so I think that covers what you want.

@ridiculousfish ridiculousfish added this to the fish 3.2.0 milestone Apr 30, 2020
@soumya92
Copy link
Contributor Author

soumya92 commented Apr 30, 2020

Do we want to invoke fish_job_summary for all jobs and let it filter out foreground ones?

I like that idea! It would work very well for me, since I can then avoid duplicated code between this function and postexec. I can also simplify my own postexec which currently has special handling for "^C" on the foreground job.

A flag indicating fg vs bg would also very much help with customisations, since bg means the function could need to handle an existing prompt on the screen. (It could also defer printing the line until next prompt to avoid interleaving with command output, or print some more obvious borders to make it clear that the output is coming from a background job rather than whatever is running).

I ended up not calling the function for foreground job ends, because that is covered by postexec already (and it became complicated to filter out, e.g. 'down-or-search', and it caused a segfault, so something there is tough to get working).

@soumya92
Copy link
Contributor Author

Can you take a look at this PR?

I've fixed the tests (mostly, clang is still failing for some reason I don't fully understand), and I think I've addressed the comments raised earlier.

Copy link
Member

@krobelus krobelus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I only have some nitpicks.
The failure could be due to high load on the travis instance, in that case increasing the sleep amounts should work.

share/functions/fish_job_summary.fish Outdated Show resolved Hide resolved
share/functions/fish_job_summary.fish Outdated Show resolved Hide resolved
share/functions/fish_job_summary.fish Outdated Show resolved Hide resolved
src/proc.cpp Outdated Show resolved Hide resolved
share/functions/fish_job_summary.fish Outdated Show resolved Hide resolved
…alled

This allows users to customise the behaviour of the shell by redefining the function. This is similar to how fish_title or fish_greeting behave, where the default implementation can be easily overridden.

The function receives as arguments the job id, command line, signal name and signal description.
The default implementation will not print any output in that case, but this provides users with additional flexibility when it comes to customising the shell's behaviour.
@soumya92
Copy link
Contributor Author

Done. Increasing sleep times seems to have fixed the tests as well, thanks!

@krobelus krobelus merged commit 518170b into fish-shell:master May 19, 2020
@krobelus
Copy link
Member

Splendid, thank you!

@soumya92 soumya92 deleted the job-exit-summary branch May 19, 2020 18:40
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

implement generic job_completed event
3 participants