mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-27 14:45:13 +08:00
trap: Remove superfluous helper functions and stringify
This commit is contained in:
parent
4bad88f0df
commit
a6820cbe62
@ -1,20 +1,4 @@
|
|||||||
# This defines a compatibility shim for the `trap` command found in other shells like bash and zsh.
|
# This defines a compatibility shim for the `trap` command found in other shells like bash and zsh.
|
||||||
|
|
||||||
function __trap_translate_signal
|
|
||||||
set -l upper (echo $argv[1]|tr a-z A-Z)
|
|
||||||
string replace -r '^SIG' '' -- $upper
|
|
||||||
end
|
|
||||||
|
|
||||||
function __trap_switch
|
|
||||||
switch $argv[1]
|
|
||||||
case EXIT exit
|
|
||||||
echo --on-event fish_exit
|
|
||||||
|
|
||||||
case '*'
|
|
||||||
echo --on-signal $argv[1]
|
|
||||||
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'
|
||||||
set -l options h/help l/list-signals p/print
|
set -l options h/help l/list-signals p/print
|
||||||
argparse -n trap $options -- $argv
|
argparse -n trap $options -- $argv
|
||||||
@ -52,8 +36,7 @@ function trap -d 'Perform an action when the shell receives a signal'
|
|||||||
|
|
||||||
switch $mode
|
switch $mode
|
||||||
case clear
|
case clear
|
||||||
for i in $argv
|
for sig in (string upper -- $argv | string replace -r '^SIG' '')
|
||||||
set sig (__trap_translate_signal $i)
|
|
||||||
if test -n "$sig"
|
if test -n "$sig"
|
||||||
functions -e __trap_handler_$sig
|
functions -e __trap_handler_$sig
|
||||||
end
|
end
|
||||||
@ -63,11 +46,12 @@ function trap -d 'Perform an action when the shell receives a signal'
|
|||||||
set -l cmd $argv[1]
|
set -l cmd $argv[1]
|
||||||
set -e argv[1]
|
set -e argv[1]
|
||||||
|
|
||||||
for i in $argv
|
for sig in (string upper -- $argv | string replace -r '^SIG' '')
|
||||||
set -l sig (__trap_translate_signal $i)
|
|
||||||
set -l sw (__trap_switch $sig)
|
|
||||||
|
|
||||||
if test -n "$sig"
|
if test -n "$sig"
|
||||||
|
set -l sw --on-signal $sig
|
||||||
|
if string match -qi exit -- $sig
|
||||||
|
set sw --on-event fish_exit
|
||||||
|
end
|
||||||
echo "function __trap_handler_$sig $sw; $cmd; end" | source
|
echo "function __trap_handler_$sig $sw; $cmd; end" | source
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
@ -82,9 +66,7 @@ function trap -d 'Perform an action when the shell receives a signal'
|
|||||||
set names (functions -na | string match "__trap_handler_*" | string replace '__trap_handler_' '')
|
set names (functions -na | string match "__trap_handler_*" | string replace '__trap_handler_' '')
|
||||||
end
|
end
|
||||||
|
|
||||||
for i in $names
|
for sig in (string upper -- $names | string replace -r '^SIG' '')
|
||||||
set sig (__trap_translate_signal $i)
|
|
||||||
|
|
||||||
if test -n "$sig"
|
if test -n "$sig"
|
||||||
functions __trap_handler_$i
|
functions __trap_handler_$i
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user