diff --git a/share/functions/fish_job_summary.fish b/share/functions/fish_job_summary.fish index a27ca89b1..065dba74f 100644 --- a/share/functions/fish_job_summary.fish +++ b/share/functions/fish_job_summary.fish @@ -1,5 +1,6 @@ -function fish_job_summary -a job_id cmd_line signal_or_end_name signal_desc proc_pid proc_name +function fish_job_summary -a job_id is_foreground cmd_line signal_or_end_name signal_desc proc_pid proc_name # job_id: ID of the job that stopped/terminated/ended. + # is_foreground: 1 if the job was running in the foreground, 0 otherwise. # cmd_line: The command line of the job. # signal_or_end_name: If terminated by signal, the name of the signal (e.g. SIGTERM). # If ended, the string "ENDED". If stopped, the string "STOPPED". @@ -10,6 +11,19 @@ function fish_job_summary -a job_id cmd_line signal_or_end_name signal_desc proc # proc_name: the name of that process. # If the job has only one process, these two arguments will not be provided. + # Print nothing if we get SIGINT in the foreground process group, to avoid spamming + # obvious stuff on the console (#1119). If we get SIGINT for the foreground + # process, assume the user typed ^C and can see it working. It's possible they + # didn't, and the signal was delivered via pkill, etc., but the SIGINT/SIGTERM + # distinction is precisely to allow INT to be from a UI + # and TERM to be programmatic, so this assumption is keeping with the design of + # signals. If echoctl is on, then the terminal will have written ^C to the console. + # If off, it won't have. We don't echo ^C either way, so as to respect the user's + # preference. + if test $signal_or_end_name = "SIGINT"; and test $is_foreground -eq 1 + return + end + set -l ellipsis '...' if string match -iqr 'utf.?8' -- $LANG set ellipsis \u2026 diff --git a/src/proc.cpp b/src/proc.cpp index 7b4c00caa..49a00f750 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -477,6 +477,7 @@ using job_status_t = enum { JOB_STOPPED, JOB_ENDED }; static void print_job_status(parser_t &parser, const job_t *j, job_status_t status) { wcstring_list_t args = { format_string(L"%d", j->job_id()), + format_string(L"%d", j->is_foreground()), j->command(), status == JOB_STOPPED ? L"STOPPED" : L"ENDED", }; @@ -539,34 +540,22 @@ static bool try_clean_process_in_job(parser_t &parser, process_t *p, job_t *j, return false; } - // Print nothing if we get SIGINT in the foreground process group, to avoid spamming - // obvious stuff on the console (#1119). If we get SIGINT for the foreground - // process, assume the user typed ^C and can see it working. It's possible they - // didn't, and the signal was delivered via pkill, etc., but the SIGINT/SIGTERM - // distinction is precisely to allow INT to be from a UI - // and TERM to be programmatic, so this assumption is keeping with the design of - // signals. If echoctl is on, then the terminal will have written ^C to the console. - // If off, it won't have. We don't echo ^C either way, so as to respect the user's - // preference. - bool printed = false; - if (s.signal_code() != SIGINT || !j->is_foreground()) { - wcstring_list_t args; - args.reserve(proc_is_job ? 4 : 6); - args.push_back(format_string(L"%d", j->job_id())); - args.push_back(j->command()); - args.push_back(sig2wcs(s.signal_code())); - args.push_back(signal_get_desc(s.signal_code())); - if (!proc_is_job) { - args.push_back(format_string(L"%d", p->pid)); - args.push_back(p->argv0()); - } - print_job_summary(parser, args); - printed = true; + wcstring_list_t args; + args.reserve(proc_is_job ? 5 : 7); + args.push_back(format_string(L"%d", j->job_id())); + args.push_back(format_string(L"%d", j->is_foreground())); + args.push_back(j->command()); + args.push_back(sig2wcs(s.signal_code())); + args.push_back(signal_get_desc(s.signal_code())); + if (!proc_is_job) { + args.push_back(format_string(L"%d", p->pid)); + args.push_back(p->argv0()); } + print_job_summary(parser, args); // Clear status so it is not reported more than once. // TODO: this seems like a clumsy way to ensure that. p->status = proc_status_t::from_exit_code(0); - return printed; + return true; } /// \return whether this job wants a status message printed when it stops or completes. diff --git a/tests/job_summary.expect b/tests/job_summary.expect index 296bea8b8..b017b3622 100644 --- a/tests/job_summary.expect +++ b/tests/job_summary.expect @@ -13,7 +13,7 @@ send_line "sleep 0.5 &" sleep 0.050 expect_prompt sleep 0.550 -expect -re "\[0-9]+:sleep 0.5 &:ENDED" +expect -re "\[0-9]+:0:sleep 0.5 &:ENDED" send_line "" expect_prompt @@ -24,7 +24,7 @@ sleep 0.100 expect_prompt exec -- pkill -TERM sleep -P $pid sleep 0.100 -expect -re "\[0-9]+:sleep 10 &:SIGTERM:Polite quit request" +expect -re "\[0-9]+:0:sleep 10 &:SIGTERM:Polite quit request" send_line "" expect_prompt @@ -34,6 +34,6 @@ send_line "true | sleep 6" sleep 0.100 exec -- pkill -KILL sleep -P $pid sleep 0.100 -expect -re "\[0-9]+:true | sleep 6:SIGKILL:Forced quit:\[0-9]+:sleep" +expect -re "\[0-9]+:1:true|sleep 6:SIGKILL:Forced quit:\[0-9]+:sleep" send_line "" expect_prompt