From 0071ad040940baf82c9c8192e76fae9971571d16 Mon Sep 17 00:00:00 2001 From: zabereer Date: Tue, 26 Feb 2019 05:59:46 +0000 Subject: [PATCH] add __fish_status_to_signal.fish and __fish_pipestatus_with_signal.fish --- .../__fish_pipestatus_with_signal.fish | 5 +++++ share/functions/__fish_status_to_signal.fish | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 share/functions/__fish_pipestatus_with_signal.fish create mode 100644 share/functions/__fish_status_to_signal.fish diff --git a/share/functions/__fish_pipestatus_with_signal.fish b/share/functions/__fish_pipestatus_with_signal.fish new file mode 100644 index 000000000..e85d1b79c --- /dev/null +++ b/share/functions/__fish_pipestatus_with_signal.fish @@ -0,0 +1,5 @@ +function __fish_pipestatus_with_signal --description "Print arguments from \$pipestatus replacing values with signal names where appropriate" + for pstat in $argv + echo (__fish_status_to_signal $pstat) + end +end diff --git a/share/functions/__fish_status_to_signal.fish b/share/functions/__fish_status_to_signal.fish new file mode 100644 index 000000000..de07dcb64 --- /dev/null +++ b/share/functions/__fish_status_to_signal.fish @@ -0,0 +1,22 @@ +function __fish_status_to_signal --description "Print signal name from argument (\$status), or just argument" + if test (count $argv) -ne 1 + echo "expected single argument as integer from \$status" >&2 + return 1 + end + + if test $argv[1] -gt 128 + set -l signals SIGHUP SIGINT SIGQUIT SIGILL SIGTRAP SIGABRT SIGBUS \ + SIGFPE SIGKILL SIGUSR1 SIGSEGV SIGUSR2 SIGPIPE SIGALRM \ + SIGTERM SIGSTKFLT SIGCHLD SIGCONT SIGSTOP SIGTSTP \ + SIGTTIN SIGTTOU SIGURG SIGXCPU SIGXFSZ SIGVTALRM \ + SIGPROF SIGWINCH SIGIO SIGPWR SIGSYS + set -l sigix (math $argv[1] - 128) + if test $sigix -le (count $signals) + echo $signals[$sigix] + return 0 + end + end + + echo $argv[1] + return 0 +end