fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
1185e5279
master
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. 23if test " $signal_or_end_name " = SIGINT;and test $is_foreground -eq 1 24return 25end 26 27set -l max_cmd_len32 28set cmd_line( string shorten -m$max_cmd_len --$cmd_line | string collect) 29 30set -l message 31switch $signal_or_end_name 32case STOPPED 33set message( printf ( _ "fish: Job %s, '%s' has stopped\n" ) $job_id $cmd_line ) 34case ENDED 35set message( printf ( _ "fish: Job %s, '%s' has ended\n" ) $job_id $cmd_line ) 36case 'SIG*' 37if test -n " $proc_pid " 38set 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 ) 40else 41set message( printf ( _ "fish: Job %s, '%s' terminated by signal %s (%s)\n" ) \ 42$job_id $cmd_line $signal_or_end_name $signal_desc ) 43end 44end 45 46if test $is_foreground -eq 0 ;and test $signal_or_end_name != STOPPED 47__fish_echo string join\n --$message 48else 49string join>&2 \n --$message 50end 51end