fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes AltmanningerDon't print multiple summaries for multiline jobs1185e5279

master
2.6 KiB51 linesraw
1function fish_job_summary -a job_id is_foreground cmd_line signal_or_end_name signal_desc proc_pid proc_name
2    # job_id: ID of the job that stopped/terminated/ended.
3    # is_foreground: 1 if the job was running in the foreground, 0 otherwise.
4    # cmd_line: The command line of the job.
5    # signal_or_end_name: If terminated by signal, the name of the signal (e.g. SIGTERM).
6    #   If ended, the string "ENDED". If stopped, the string "STOPPED".
7    # signal_desc: A description of the signal (e.g. "Polite quite request").
8    #   Not provided if the job stopped or ended without a signal.
9    # If the job has more than one process:
10    # proc_pid: the pid of the process affected.
11    # proc_name: the name of that process.
12    # If the job has only one process, these two arguments will not be provided.
13
14    # Print nothing if we get SIGINT in the foreground process group, to avoid spamming
15    # obvious stuff on the console (#1119). If we get SIGINT for the foreground
16    # process, assume the user typed ^C and can see it working. It's possible they
17    # didn't, and the signal was delivered via pkill, etc., but the SIGINT/SIGTERM
18    # distinction is precisely to allow INT to be from a UI
19    # and TERM to be programmatic, so this assumption is keeping with the design of
20    # signals. If echoctl is on, then the terminal will have written ^C to the console.
21    # If off, it won't have. We don't echo ^C either way, so as to respect the user's
22    # preference.
23    if test "$signal_or_end_name" = SIGINT; and test $is_foreground -eq 1
24        return
25    end
26
27    set -l max_cmd_len 32
28    set cmd_line (string shorten -m$max_cmd_len -- $cmd_line | string collect)
29
30    set -l message
31    switch $signal_or_end_name
32        case STOPPED
33            set message (printf ( _ "fish: Job %s, '%s' has stopped\n" ) $job_id $cmd_line)
34        case ENDED
35            set message (printf ( _ "fish: Job %s, '%s' has ended\n" ) $job_id $cmd_line)
36        case 'SIG*'
37            if test -n "$proc_pid"
38                set message (printf ( _ "fish: Process %s, '%s' from job %s, '%s' terminated by signal %s (%s)\n" ) \
39                    $proc_pid $proc_name $job_id $cmd_line $signal_or_end_name $signal_desc)
40            else
41                set message (printf ( _ "fish: Job %s, '%s' terminated by signal %s (%s)\n" ) \
42                    $job_id $cmd_line $signal_or_end_name $signal_desc)
43            end
44    end
45
46    if test $is_foreground -eq 0; and test $signal_or_end_name != STOPPED
47        __fish_echo string join \n -- $message
48    else
49        string join >&2 \n -- $message
50    end
51end