mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-12 13:08:49 +00:00
parent
516e989464
commit
6123d3cb50
2 changed files with 10 additions and 12 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
\subsection trap-synopsis Synopsis
|
\subsection trap-synopsis Synopsis
|
||||||
\fish{synopsis}
|
\fish{synopsis}
|
||||||
trap [OPTIONS] [[ARG] SIGSPEC ... ]
|
trap [OPTIONS] [[ARG] REASON ... ]
|
||||||
\endfish
|
\endfish
|
||||||
|
|
||||||
\subsection trap-description Description
|
\subsection trap-description Description
|
||||||
|
@ -13,21 +13,21 @@ The following parameters are available:
|
||||||
|
|
||||||
- `ARG` is the command to be executed on signal delivery.
|
- `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.
|
- `-l` or `--list-signals` prints a list of signal names.
|
||||||
|
|
||||||
- `-p` or `--print` prints all defined signal handlers.
|
- `-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.
|
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
|
\subsection trap-example Example
|
||||||
|
|
||||||
|
|
|
@ -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
|
function __trap_translate_signal
|
||||||
set upper (echo $argv[1]|tr a-z A-Z)
|
set upper (echo $argv[1]|tr a-z A-Z)
|
||||||
|
@ -5,15 +6,13 @@ function __trap_translate_signal
|
||||||
end
|
end
|
||||||
|
|
||||||
function __trap_switch
|
function __trap_switch
|
||||||
|
|
||||||
switch $argv[1]
|
switch $argv[1]
|
||||||
case EXIT
|
case EXIT exit
|
||||||
echo --on-process-exit %self
|
echo --on-process-exit %self
|
||||||
|
|
||||||
case '*'
|
case '*'
|
||||||
echo --on-signal $argv[1]
|
echo --on-signal $argv[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function trap -d 'Perform an action when the shell receives a signal'
|
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]
|
set -e opt[1]
|
||||||
|
|
||||||
for i in $opt
|
for i in $opt
|
||||||
|
|
||||||
set -l sig (__trap_translate_signal $i)
|
set -l sig (__trap_translate_signal $i)
|
||||||
set sw (__trap_switch $sig)
|
set sw (__trap_switch $sig)
|
||||||
|
|
||||||
if test $sig
|
if test $sig
|
||||||
eval "function __trap_handler_$sig $sw; $cmd; end"
|
echo "function __trap_handler_$sig $sw; $cmd; end" | source
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue