Make more of the functions in share/functions print error messages to stderr

This commit is contained in:
Thom Chiovoloni 2022-04-03 20:57:55 -07:00 committed by Fabian Boehm
parent 84bd1715d8
commit a770ff144e
17 changed files with 31 additions and 31 deletions

View File

@ -5,7 +5,7 @@ function __fish_md5
if test $argv[1] = -s if test $argv[1] = -s
echo (echo $argv[2] | md5sum | string split ' ')[1] echo (echo $argv[2] | md5sum | string split ' ')[1]
else else
printf (_ "%s: Too many arguments %s\n") fish_md5 $argv printf (_ "%s: Too many arguments %s\n") fish_md5 $argv >&2
end end
else else
echo (md5sum $argv[1] | string split ' ')[1] echo (md5sum $argv[1] | string split ' ')[1]
@ -17,7 +17,7 @@ function __fish_md5
if test $argv[1] = -s if test $argv[1] = -s
md5 -s $argv[2] md5 -s $argv[2]
else else
printf (_ "%s: Too many arguments %s\n") fish_md5 $argv printf (_ "%s: Too many arguments %s\n") fish_md5 $argv >&2
end end
else else
md5 -q $argv[1] md5 -q $argv[1]

View File

@ -37,7 +37,7 @@ function __fish_print_help --description "Print help message for the specified f
set -a format -rLL={$cols}n set -a format -rLL={$cols}n
end end
else else
echo fish: (_ "Cannot format help; no parser found") echo fish: (_ "Cannot format help; no parser found") >&2
return 1 return 1
end end

View File

@ -5,7 +5,7 @@ function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mod
if contains -- -h $argv if contains -- -h $argv
or contains -- --help $argv or contains -- --help $argv
echo "Sorry but this function doesn't support -h or --help" echo "Sorry but this function doesn't support -h or --help" >&2
return 1 return 1
end end

View File

@ -10,21 +10,21 @@ function _validate_int --no-scope-shadowing
if not string match -qr '^-?\d+$' -- $_flag_value if not string match -qr '^-?\d+$' -- $_flag_value
set -l msg (_ "%s: Value '%s' for flag '%s' is not an integer\n") set -l msg (_ "%s: Value '%s' for flag '%s' is not an integer\n")
printf $msg $_argparse_cmd $_flag_value $_flag_name printf $msg $_argparse_cmd $_flag_value $_flag_name >&2
return 1 return 1
end end
if set -q _flag_min if set -q _flag_min
and test $_flag_value -lt $_flag_min and test $_flag_value -lt $_flag_min
set -l msg (_ "%s: Value '%s' for flag '%s' less than min allowed of '%s'\n") set -l msg (_ "%s: Value '%s' for flag '%s' less than min allowed of '%s'\n")
printf $msg $_argparse_cmd $_flag_value $_flag_name $_flag_min printf $msg $_argparse_cmd $_flag_value $_flag_name $_flag_min >&2
return 1 return 1
end end
if set -q _flag_max if set -q _flag_max
and test $_flag_value -gt $_flag_max and test $_flag_value -gt $_flag_max
set -l msg (_ "%s: Value '%s' for flag '%s' greater than max allowed of '%s'\n") set -l msg (_ "%s: Value '%s' for flag '%s' greater than max allowed of '%s'\n")
printf $msg $_argparse_cmd $_flag_value $_flag_name $_flag_max printf $msg $_argparse_cmd $_flag_value $_flag_name $_flag_max >&2
return 1 return 1
end end

View File

@ -5,7 +5,7 @@ function cd --description "Change directory"
set -l MAX_DIR_HIST 25 set -l MAX_DIR_HIST 25
if test (count $argv) -gt (test "$argv[1]" = "--" && echo 2 || echo 1) if test (count $argv) -gt (test "$argv[1]" = "--" && echo 2 || echo 1)
printf "%s\n" (_ "Too many args for cd command") printf "%s\n" (_ "Too many args for cd command") >&2
return 1 return 1
end end

View File

@ -34,9 +34,9 @@ function cdh --description "Menu based cd command"
set -l dirc (count $uniq_dirs) set -l dirc (count $uniq_dirs)
if test $dirc -gt (count $letters) if test $dirc -gt (count $letters)
set -l msg (_ 'This should not happen. Have you changed the cd function?') set -l msg (_ 'This should not happen. Have you changed the cd function?')
printf "$msg\n" printf "$msg\n" >&2
set -l msg (_ 'There are %s unique dirs in your history but I can only handle %s') set -l msg (_ 'There are %s unique dirs in your history but I can only handle %s')
printf "$msg\n" $dirc (count $letters) printf "$msg\n" $dirc (count $letters) >&2
return 1 return 1
end end
@ -77,11 +77,11 @@ function cdh --description "Menu based cd command"
cd $uniq_dirs[$choice] cd $uniq_dirs[$choice]
return return
else else
printf "$msg\n" $dirc $choice printf "$msg\n" $dirc $choice >&2
return 1 return 1
end end
else else
printf "$msg\n" $dirc $choice printf "$msg\n" $dirc $choice >&2
return 1 return 1
end end
end end

View File

@ -5,7 +5,7 @@ function fish_update_completions --description "Update man-page based completion
if set -l python (__fish_anypython) if set -l python (__fish_anypython)
$python $update_args $python $update_args
else else
printf "%s\n" (_ "python executable not found") printf "%s\n" (_ "python executable not found") >&2
return 1 return 1
end end
end end

View File

@ -1,7 +1,7 @@
function fish_vi_key_bindings --description 'vi-like key bindings for fish' function fish_vi_key_bindings --description 'vi-like key bindings for fish'
if contains -- -h $argv if contains -- -h $argv
or contains -- --help $argv or contains -- --help $argv
echo "Sorry but this function doesn't support -h or --help" echo "Sorry but this function doesn't support -h or --help" >&2
return 1 return 1
end end

View File

@ -54,7 +54,7 @@ function funced --description 'Edit function definition'
set -l editor_cmd set -l editor_cmd
echo $editor | read -ta editor_cmd echo $editor | read -ta editor_cmd
if not type -q -f "$editor_cmd[1]" if not type -q -f "$editor_cmd[1]"
echo (_ "funced: The value for \$EDITOR '$editor' could not be used because the command '$editor_cmd[1]' could not be found") echo (_ "funced: The value for \$EDITOR '$editor' could not be used because the command '$editor_cmd[1]' could not be found") >&2
set editor fish set editor fish
end end

View File

@ -13,7 +13,7 @@ function help --description 'Show help for the fish shell'
if string match -q string $argv[1] if string match -q string $argv[1]
set fish_help_item (string join '-' $argv[1] $argv[2]) set fish_help_item (string join '-' $argv[1] $argv[2])
else else
echo "help: Expected at most 1 args, got 2" echo "help: Expected at most 1 args, got 2" >&2
return 1 return 1
end end
end end
@ -93,8 +93,8 @@ function help --description 'Show help for the fish shell'
end end
if not set -q fish_browser[1] if not set -q fish_browser[1]
printf (_ '%s: Could not find a web browser.\n') help printf (_ '%s: Could not find a web browser.\n') help >&2
printf (_ 'Please try `BROWSER=some_browser help`, `man fish-doc`, or `man fish-tutorial`.\n\n') printf (_ 'Please try `BROWSER=some_browser help`, `man fish-doc`, or `man fish-tutorial`.\n\n') >&2
return 1 return 1
end end

View File

@ -13,7 +13,7 @@ function nextd --description "Move forward in the directory history"
if test $argv[1] -ge 0 2>/dev/null if test $argv[1] -ge 0 2>/dev/null
set times $argv[1] set times $argv[1]
else else
printf (_ "%s: The number of positions to skip must be a non-negative integer\n") nextd printf (_ "%s: The number of positions to skip must be a non-negative integer\n") nextd >&2
return 1 return 1
end end
end end

View File

@ -14,7 +14,7 @@ if not command -sq open
end end
if not set -q argv[1] if not set -q argv[1]
printf (_ "%ls: Expected at least %d args, got only %d\n") open 1 0 printf (_ "%ls: Expected at least %d args, got only %d\n") open 1 0 >&2
return 1 return 1
end end
@ -34,7 +34,7 @@ if not command -sq open
disown $last_pid 2>/dev/null disown $last_pid 2>/dev/null
end end
else else
echo (_ 'No open utility found. Try installing "xdg-open" or "xdg-utils".') echo (_ 'No open utility found. Try installing "xdg-open" or "xdg-utils".') >&2
end end
end end
end end

View File

@ -13,7 +13,7 @@ function prevd --description "Move back in the directory history"
if test $argv[1] -ge 0 2>/dev/null if test $argv[1] -ge 0 2>/dev/null
set times $argv[1] set times $argv[1]
else else
printf (_ "%s: The number of positions to skip must be a non-negative integer\n") nextd printf (_ "%s: The number of positions to skip must be a non-negative integer\n") prevd >&2
return 1 return 1
end end
end end

View File

@ -25,7 +25,7 @@ function pushd --description 'Push directory to stack'
if not set -q argv[1] if not set -q argv[1]
# check that the stack isn't empty # check that the stack isn't empty
if not set -q dirstack[1] if not set -q dirstack[1]
echo "pushd: no other directory" echo "pushd: no other directory" >&2
return 1 return 1
end end
@ -48,7 +48,7 @@ function pushd --description 'Push directory to stack'
if test -n "$rot_r" if test -n "$rot_r"
# check the rotation in range # check the rotation in range
if test $rot_r -ge (count $stack) if test $rot_r -ge (count $stack)
echo "pushd: -$rot_r: directory stack index out of range" echo "pushd: -$rot_r: directory stack index out of range" >&2
return 1 return 1
end end
@ -57,7 +57,7 @@ function pushd --description 'Push directory to stack'
# check the rotation in range # check the rotation in range
if test $rot_l -ge (count $stack) if test $rot_l -ge (count $stack)
echo "pushd: +$rot_l: directory stack index out of range" echo "pushd: +$rot_l: directory stack index out of range" >&2
return 1 return 1
else else
# rotate stack unless rot_l is 0 # rotate stack unless rot_l is 0

View File

@ -49,7 +49,7 @@ function realpath -d "return an absolute path without symlinks"
end end
if not set -q argv[1] if not set -q argv[1]
printf (_ "%ls: Expected at least %d args, got only %d\n") realpath 1 0 printf (_ "%ls: Expected at least %d args, got only %d\n") realpath 1 0 >&2
return 1 return 1
end end

View File

@ -36,13 +36,13 @@ if not command -sq seq
set step $argv[2] set step $argv[2]
set to $argv[3] set to $argv[3]
case '*' case '*'
printf (_ "%s: Expected 1, 2 or 3 arguments, got %d\n") seq (count $argv) printf (_ "%s: Expected 1, 2 or 3 arguments, got %d\n") seq (count $argv) >&2
return 1 return 1
end end
for i in $from $step $to for i in $from $step $to
if not string match -rq -- '^-?[0-9]*([0-9]*|\.[0-9]+)$' $i if not string match -rq -- '^-?[0-9]*([0-9]*|\.[0-9]+)$' $i
printf (_ "%s: '%s' is not a number\n") seq $i printf (_ "%s: '%s' is not a number\n") seq $i >&2
return 1 return 1
end end
end end

View File

@ -12,7 +12,7 @@ function vared --description "Edit variable value"
return 0 return 0
case '-*' case '-*'
printf (_ "%s: Unknown option %s\n") vared $argv printf (_ "%s: Unknown option %s\n") vared $argv >&2
return 1 return 1
case '*' case '*'
@ -30,10 +30,10 @@ function vared --description "Edit variable value"
-c "$$argv" \ -c "$$argv" \
$argv $argv
else else
printf (_ '%s: %s is an array variable. Use %svared%s %s[n]%s to edit the n:th element of %s\n') vared $argv (set_color $fish_color_command; echo) (set_color $fish_color_normal; echo) $argv (set_color normal; echo) $argv printf (_ '%s: %s is an array variable. Use %svared%s %s[n]%s to edit the n:th element of %s\n') vared $argv (set_color $fish_color_command; echo) (set_color $fish_color_normal; echo) $argv (set_color normal; echo) $argv >&2
end end
end end
else else
printf (_ '%s: Expected exactly one argument, got %s.\n\nSynopsis:\n\t%svared%s VARIABLE\n') vared (count $argv) (set_color $fish_color_command; echo) (set_color $fish_color_normal; echo) printf (_ '%s: Expected exactly one argument, got %s.\n\nSynopsis:\n\t%svared%s VARIABLE\n') vared (count $argv) (set_color $fish_color_command; echo) (set_color $fish_color_normal; echo) >&2
end end
end end