From 6496adf101d6cd04b2d579509454c17f1965281f Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 28 Apr 2013 16:31:25 -0700 Subject: [PATCH] Make trap sort of work on OS X https://github.com/fish-shell/fish-shell/issues/607 --- share/functions/trap.fish | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/share/functions/trap.fish b/share/functions/trap.fish index 5432df1a6..640567f3c 100644 --- a/share/functions/trap.fish +++ b/share/functions/trap.fish @@ -25,21 +25,32 @@ function trap -d 'Perform an action when the shell receives a signal' set -l mode set -l cmd set -l sig - set -l shortopt - set -l longopt - set -l shortopt -o lph + set -l options set -l longopt - if not getopt -T >/dev/null - set longopt -l print,help,list-signals + set -l shortopt lph + if not getopt -T > /dev/null + # GNU getopt + set longopt print,help,list-signals + set options -o $shortopt -l $longopt -- + # Verify options + if not getopt -n type $options $argv >/dev/null + return 1 + end + else + # Old getopt, used on OS X + set options $shortopt + # Verify options + if not getopt $options $argv >/dev/null + return 1 + end end - if not getopt -n type -Q $shortopt $longopt -- $argv >/dev/null - return 1 - end - - set -l tmp (getopt $shortopt $longopt -- $argv) + # Do the real getopt invocation + set -l tmp (getopt $options $argv) + # Break tmp up into an array + set -l opt eval set opt $tmp while count $opt >/dev/null