diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2013-01-12 14:18:34 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2013-01-12 14:18:34 -0800 |
commit | dc37a8079e4b1a69300a4bf1bdd00f8e2c66e1d5 (patch) | |
tree | b2903cfe9c29a1c62d5a57250a8ef3c2d2b90878 | |
parent | 373cca0bf6834269c2b4fb6f27bcbf1c548ff983 (diff) |
Added a seq function that defers to the seq command if present
-rw-r--r-- | common.cpp | 5 | ||||
-rw-r--r-- | common.h | 1 | ||||
-rwxr-xr-x | seq.in | 89 | ||||
-rw-r--r-- | share/functions/type.fish | 39 | ||||
-rw-r--r-- | tests/test7.in | 12 | ||||
-rw-r--r-- | tests/test7.out | 3 |
6 files changed, 92 insertions, 57 deletions
@@ -293,6 +293,11 @@ char *wcs2str(const wchar_t *in) return wcs2str_internal(in, out); } +char *wcs2str(const wcstring &in) +{ + return wcs2str(in.c_str()); +} + /* This function is distinguished from wcs2str_internal in that it allows embedded null bytes */ std::string wcs2string(const wcstring &input) { @@ -226,6 +226,7 @@ wcstring str2wcstring(const std::string &in); way using the private use area. */ char *wcs2str(const wchar_t *in); +char *wcs2str(const wcstring &in); std::string wcs2string(const wcstring &input); /** Test if a string prefixes another. Returns true if a is a prefix of b */ @@ -1,52 +1,47 @@ -#!/usr/bin/env fish -# -# Fallback implementation of the seq command -# -# @configure_input@ - -set -l from 1 -set -l step 1 -set -l to 1 - -function _ -d "Alias for the gettext command" - printf "%s" $argv -end -if test 1 = "@HAVE_GETTEXT@" - if which gettext ^/dev/null >/dev/null - function _ -d "Alias for the gettext command" - gettext fish $argv +# If seq is not installed, then define a function that invokes __fish_fallback_seq +if begin ; test -x /usr/bin/seq ; or type --no-functions seq > /dev/null; end + function seq --description "Print sequences of numbers" + __fish_fallback_seq $argv + end +end + + +function __fish_fallback_seq --description "Fallback implementation of the seq command" + + set -l from 1 + set -l step 1 + set -l to 1 + + switch (count $argv) + case 1 + set to $argv[1] + + case 2 + set from $argv[1] + set to $argv[2] + + case 3 + set from $argv[1] + set step $argv[2] + set to $argv[3] + + case '*' + printf (_ "%s: Expected 1, 2 or 3 arguments, got %d\n") seq (count $argv) + exit 1 + + end + + for i in $from $step $to + if not echo $i | grep -E '^-?[0-9]*([0-9]*|\.[0-9]+)$' >/dev/null + printf (_ "%s: '%s' is not a number\n") seq $i + exit 1 end end -end - -switch (count $argv) - case 1 - set to $argv[1] - - case 2 - set from $argv[1] - set to $argv[2] - - case 3 - set from $argv[1] - set step $argv[2] - set to $argv[3] - - case '*' - printf (_ "%s: Expected 1, 2 or 3 arguments, got %d\n") seq (count $argv) - exit 1 - -end - -for i in $from $step $to - if not echo $i | grep -E '^-?[0-9]*([0-9]*|\.[0-9]+)$' >/dev/null - printf (_ "%s: '%s' is not a number\n") seq $i - exit 1 + + if [ $step -ge 0 ] + echo "for( i=$from; i<=$to ; i+=$step ) i;" | bc + else + echo "for( i=$from; i>=$to ; i+=$step ) i;" | bc end end -if [ $step -ge 0 ] - echo "for( i=$from; i<=$to ; i+=$step ) i;" | bc -else - echo "for( i=$from; i>=$to ; i+=$step ) i;" | bc -end diff --git a/share/functions/type.fish b/share/functions/type.fish index 0c25b7ff..881bac04 100644 --- a/share/functions/type.fish +++ b/share/functions/type.fish @@ -5,25 +5,44 @@ function type --description "Print the type of a command" set -l res 1 set -l mode normal set -l selection all - + + set -l new_getopt + if not getopt -T > /dev/null + set new_getopt 1 + else + set new_getopt '' + end + # # Get options # - set -l shortopt -o tpPafh + set -l options + set -l shortopt tpPafh set -l longopt - if not getopt -T >/dev/null - set longopt -l type,path,force-path,all,no-functions,help - end - - if not getopt -n type -Q $shortopt $longopt -- $argv >/dev/null - return 1 + if test $new_getopt + # GNU getopt + set longopt type,path,force-path,all,no-functions,help + 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 - 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 - + for i in $opt switch $i case -t --type diff --git a/tests/test7.in b/tests/test7.in index d642e71e..22f5d92c 100644 --- a/tests/test7.in +++ b/tests/test7.in @@ -110,3 +110,15 @@ if not echo skip1 > /dev/null else if echo skip2 > /dev/null echo "zeta 6.2" end + +echo '###' + +# Ensure 'type' works +# https://github.com/fish-shell/fish-shell/issues/513 +function fish_test_type_zzz + true +end +# Should succeed +type fish_test_type_zzz >/dev/null ; echo $status +# Should fail +type -f fish_test_type_zzz >/dev/null ; echo $status diff --git a/tests/test7.out b/tests/test7.out index 9e101b0e..fd3b8a70 100644 --- a/tests/test7.out +++ b/tests/test7.out @@ -25,3 +25,6 @@ delta4.1 delta4.2 epsilon5.2 zeta 6.2 +### +0 +1 |