diff --git a/doc_src/trap.txt b/doc_src/trap.txt index d4380550c..3c8d8a963 100644 --- a/doc_src/trap.txt +++ b/doc_src/trap.txt @@ -2,7 +2,7 @@ \subsection trap-synopsis Synopsis \fish{synopsis} -trap [OPTIONS] [[ARG] SIGSPEC ... ] +trap [OPTIONS] [[ARG] REASON ... ] \endfish \subsection trap-description Description @@ -13,25 +13,25 @@ The following parameters are available: - `ARG` is the command to be executed on signal delivery. -- `SIGSPEC` is the name of the signal to trap. +- `REASON` is the name of the event to trap. For example, a signal like `INT` or `SIGINT`, or the special symbol `EXIT`. - `-l` or `--list-signals` prints a list of signal names. - `-p` or `--print` prints all defined signal handlers. -If `ARG` and `SIGSPEC` are both specified, `ARG` is the command to be executed when the signal specified by `SIGSPEC` is delivered. +If `ARG` and `REASON` are both specified, `ARG` is the command to be executed when the event specified by `REASON` occurs (e.g., the signal is delivered). -If `ARG` is absent (and there is a single SIGSPEC) or -, each specified signal is reset to its original disposition (the value it had upon entrance to the shell). If `ARG` is the null string the signal specified by each `SIGSPEC` is ignored by the shell and by the commands it invokes. +If `ARG` is absent (and there is a single REASON) or -, each specified signal is reset to its original disposition (the value it had upon entrance to the shell). If `ARG` is the null string the signal specified by each `REASON` is ignored by the shell and by the commands it invokes. -If `ARG` is not present and `-p` has been supplied, then the trap commands associated with each `SIGSPEC` are displayed. If no arguments are supplied or if only `-p` is given, `trap` prints the list of commands associated with each signal. +If `ARG` is not present and `-p` has been supplied, then the trap commands associated with each `REASON` are displayed. If no arguments are supplied or if only `-p` is given, `trap` prints the list of commands associated with each signal. Signal names are case insensitive and the `SIG` prefix is optional. -The return status is 1 if any `SIGSPEC` is invalid; otherwise trap returns 0. +The return status is 1 if any `REASON` is invalid; otherwise trap returns 0. \subsection trap-example Example \fish trap "status --print-stack-trace" SIGUSR1 # Prints a stack trace each time the SIGUSR1 signal is sent to the shell. -\endfish \ No newline at end of file +\endfish diff --git a/share/functions/trap.fish b/share/functions/trap.fish index 248d91f58..2e5ee52d6 100644 --- a/share/functions/trap.fish +++ b/share/functions/trap.fish @@ -1,3 +1,4 @@ +# This defines a compatibility shim for the `trap` command found in other shells like bash and zsh. function __trap_translate_signal set upper (echo $argv[1]|tr a-z A-Z) @@ -5,15 +6,13 @@ function __trap_translate_signal end function __trap_switch - switch $argv[1] - case EXIT + case EXIT exit echo --on-process-exit %self case '*' echo --on-signal $argv[1] end - end function trap -d 'Perform an action when the shell receives a signal' @@ -103,12 +102,11 @@ function trap -d 'Perform an action when the shell receives a signal' set -e opt[1] for i in $opt - set -l sig (__trap_translate_signal $i) set sw (__trap_switch $sig) if test $sig - eval "function __trap_handler_$sig $sw; $cmd; end" + echo "function __trap_handler_$sig $sw; $cmd; end" | source else return 1 end