jobs: suppress "No suitable job" if -q is given

This allows code of the form `if jobs -q $some_pid` in scripts to check whether a previously started job is still running. Previously this would return the correct value, but also print an error message.

The invalid argument errors will still be printed.
Added test cases for both.
This commit is contained in:
Soumya 2020-03-25 23:00:31 -07:00 committed by Fabian Homborg
parent 911465a8e7
commit 96563d6eff
3 changed files with 19 additions and 1 deletions

View File

@ -2,6 +2,7 @@
## Notable improvements and fixes
- `fish --no-execute` will no longer complain about unknown commands or non-matching wildcards, as these could be defined differently at runtime (especially for functions). #977
- `jobs --quiet PID` will no longer print 'no suitable job' if the job for PID does not exist (e.g. because it has finished). #6809
### Syntax changes and new commands

View File

@ -209,7 +209,9 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
builtin_jobs_print(j, mode, false, streams);
found = true;
} else {
streams.err.append_format(_(L"%ls: No suitable job: %ls\n"), cmd, argv[i]);
if (mode != JOBS_PRINT_NOTHING) {
streams.err.append_format(_(L"%ls: No suitable job: %ls\n"), cmd, argv[i]);
}
return STATUS_CMD_ERROR;
}
}

View File

@ -24,6 +24,21 @@ jobs -c
#CHECK: Command
#CHECK: sleep
#CHECK: sleep
jobs 1
echo $status
#CHECK: 1
#CHECKERR: jobs: No suitable job: 1
jobs foo
echo $status
#CHECK: 2
#CHECKERR: jobs: 'foo' is not a valid process id
jobs -q 1
echo $status
#CHECK: 1
jobs -q foo
echo $status
#CHECK: 2
#CHECKERR: jobs: 'foo' is not a valid process id
disown foo
#CHECKERR: disown: 'foo' is not a valid job specifier
disown (jobs -p)