diff --git a/common.cpp b/common.cpp index 03d2763ad..afc7430c8 100644 --- a/common.cpp +++ b/common.cpp @@ -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) { diff --git a/common.h b/common.h index c99402364..9c852f18f 100644 --- a/common.h +++ b/common.h @@ -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 */ diff --git a/seq.in b/seq.in index de8cd11c8..97bd62908 100755 --- a/seq.in +++ b/seq.in @@ -1,52 +1,47 @@ -#!/usr/bin/env fish -# -# Fallback implementation of the seq command -# -# @configure_input@ +# 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 -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 +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 0c25b7ffe..881bac049 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 + 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 - 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 - + for i in $opt switch $i case -t --type diff --git a/tests/test7.in b/tests/test7.in index d642e71e7..22f5d92c6 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 9e101b0ed..fd3b8a701 100644 --- a/tests/test7.out +++ b/tests/test7.out @@ -25,3 +25,6 @@ delta4.1 delta4.2 epsilon5.2 zeta 6.2 +### +0 +1