fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
d835c5252
master
1# localization: tier1 2 3# This defines a compatibility shim for the `trap` command found in other shells like bash and zsh. 4function trap -d'Perform an action when the shell receives a signal' 5set -l options h/help l/list-signals p/print 6argparse -n trap$options --$argv 7or return 8 9if set -q _flag_help 10__fish_print_help trap 11return 0 12end 13 14set -l mode 15set -l cmd 16set -l sig 17 18# Determine the mode based on either an explicit flag or the non-flag args. 19if set -q _flag_print 20set mode print 21else if set -q _flag_list_signals 22set mode list 23else 24switch ( count $argv ) 25case 0 26set mode print 27case 1 28set mode clear 29case '*' 30if test $argv [ 1 ] = - 31set -e argv[ 1 ] 32set mode clear 33else 34set mode set 35end 36end 37end 38 39switch $mode 40case clear 41for sigin ( string upper --$argv | string replace -r'^SIG' '' ) 42if test -n " $sig " 43functions -e __trap_handler_$sig 44end 45end 46 47case set 48set -l cmd$argv [ 1 ] 49set -e argv[ 1 ] 50 51for sigin ( string upper --$argv | string replace -r'^SIG' '' ) 52if test -n " $sig " 53set -l sw --on-signal$sig 54if string match -qi exit --$sig 55set sw --on-event fish_exit 56end 57echo "function __trap_handler_ $sig $sw ; $cmd ; end" | source 58else 59return 1 60end 61end 62 63case print 64set -l names 65if set -q argv[ 1 ] 66set names$argv 67else 68set names( functions -a| string split',' | string match"__trap_handler_*" | string replace'__trap_handler_' '' ) 69end 70 71for sigin ( string upper --$names | string replace -r'^SIG' '' ) 72if test -n " $sig " 73functions __trap_handler_$sig 74echo "" 75else 76return 1 77end 78end 79 80case list 81kill -l 82end 83end