Improved warning message when exiting with jobs still active

Fixes #4303
This commit is contained in:
peoro 2017-08-09 11:56:04 +02:00 committed by Kurtis Rader
parent 7b92217273
commit 5ceac038b1
2 changed files with 31 additions and 6 deletions

View file

@ -2178,6 +2178,21 @@ bool shell_is_exiting() {
return end_loop; 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 /// 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. /// interactive mode. It checks if it is ok to exit.
static void handle_end_loop() { static void handle_end_loop() {
@ -2202,8 +2217,7 @@ static void handle_end_loop() {
} }
if (!data->prev_end_loop && bg_jobs) { if (!data->prev_end_loop && bg_jobs) {
fputws(_(L"There are still jobs active (use the jobs command to see them).\n"), stdout); bg_job_warning();
fputws(_(L"A second attempt to exit will terminate them.\n"), stdout);
reader_exit(0, 0); reader_exit(0, 0);
data->prev_end_loop = 1; data->prev_end_loop = 1;
return; return;

View file

@ -9,8 +9,13 @@ expect_prompt
send "sleep 111 &\r" send "sleep 111 &\r"
expect_prompt expect_prompt
send "exit\r" send "exit\r"
expect "There are still jobs active" expect -re "There are still jobs active:\r
expect "A second attempt to exit will terminate them." \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 expect_prompt
# Running anything other than `exit` should result in the same warning with # Running anything other than `exit` should result in the same warning with
@ -18,8 +23,14 @@ expect_prompt
send "sleep 113 &\r" send "sleep 113 &\r"
expect_prompt expect_prompt
send "exit\r" send "exit\r"
expect "There are still jobs active" expect -re "There are still jobs active:\r
expect "A second attempt to exit will terminate them." \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 expect_prompt
# Verify that asking to exit a second time does so. # Verify that asking to exit a second time does so.