From 5ceac038b11da441ec3222d970a91e1ce24aa745 Mon Sep 17 00:00:00 2001 From: peoro Date: Wed, 9 Aug 2017 11:56:04 +0200 Subject: [PATCH] Improved warning message when exiting with jobs still active Fixes #4303 --- src/reader.cpp | 18 ++++++++++++++++-- tests/exit.expect | 19 +++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/reader.cpp b/src/reader.cpp index 89a0d767d..cd7491e44 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -2178,6 +2178,21 @@ bool shell_is_exiting() { return end_loop; } +static void bg_job_warning() { + fputws(_(L"There are still jobs active:\n"), stdout); + fputws(_(L"\n PID Command\n"), stdout); + + job_iterator_t jobs; + while (job_t *j = jobs.next()) { + if (!job_is_completed(j)) { + fwprintf(stdout, L"%6d %ls\n", j->pgid, j->command_wcstr()); + } + } + fputws(L"\n", stdout); + fputws(_(L"Use `disown PID` to let them live independently from fish.\n"), stdout); + fputws(_(L"A second attempt to exit will terminate them.\n"), stdout); +} + /// This function is called when the main loop notices that end_loop has been set while in /// interactive mode. It checks if it is ok to exit. static void handle_end_loop() { @@ -2202,8 +2217,7 @@ static void handle_end_loop() { } if (!data->prev_end_loop && bg_jobs) { - fputws(_(L"There are still jobs active (use the jobs command to see them).\n"), stdout); - fputws(_(L"A second attempt to exit will terminate them.\n"), stdout); + bg_job_warning(); reader_exit(0, 0); data->prev_end_loop = 1; return; diff --git a/tests/exit.expect b/tests/exit.expect index 3ff2074f7..6c0756675 100644 --- a/tests/exit.expect +++ b/tests/exit.expect @@ -9,8 +9,13 @@ expect_prompt send "sleep 111 &\r" expect_prompt send "exit\r" -expect "There are still jobs active" -expect "A second attempt to exit will terminate them." +expect -re "There are still jobs active:\r +\r + PID Command\r + *\\d+ sleep 111 &\r +\r +Use `disown PID` to let them live independently from fish.\r +A second attempt to exit will terminate them.\r" expect_prompt # Running anything other than `exit` should result in the same warning with @@ -18,8 +23,14 @@ expect_prompt send "sleep 113 &\r" expect_prompt send "exit\r" -expect "There are still jobs active" -expect "A second attempt to exit will terminate them." +expect -re "There are still jobs active:\r +\r + PID Command\r + *\\d+ sleep 113 &\r + *\\d+ sleep 111 &\r +\r +Use `disown PID` to let them live independently from fish.\r +A second attempt to exit will terminate them.\r" expect_prompt # Verify that asking to exit a second time does so.