From a770ff144edb206251542281cf27aa21dbfebc9e Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Sun, 3 Apr 2022 20:57:55 -0700 Subject: [PATCH] Make more of the functions in share/functions print error messages to stderr --- share/functions/__fish_md5.fish | 4 ++-- share/functions/__fish_print_help.fish | 2 +- share/functions/__fish_shared_key_bindings.fish | 2 +- share/functions/_validate_int.fish | 6 +++--- share/functions/cd.fish | 2 +- share/functions/cdh.fish | 8 ++++---- share/functions/fish_update_completions.fish | 2 +- share/functions/fish_vi_key_bindings.fish | 2 +- share/functions/funced.fish | 2 +- share/functions/help.fish | 6 +++--- share/functions/nextd.fish | 2 +- share/functions/open.fish | 4 ++-- share/functions/prevd.fish | 2 +- share/functions/pushd.fish | 6 +++--- share/functions/realpath.fish | 2 +- share/functions/seq.fish | 4 ++-- share/functions/vared.fish | 6 +++--- 17 files changed, 31 insertions(+), 31 deletions(-) diff --git a/share/functions/__fish_md5.fish b/share/functions/__fish_md5.fish index ca80f458c..3ad1a46f3 100644 --- a/share/functions/__fish_md5.fish +++ b/share/functions/__fish_md5.fish @@ -5,7 +5,7 @@ function __fish_md5 if test $argv[1] = -s echo (echo $argv[2] | md5sum | string split ' ')[1] else - printf (_ "%s: Too many arguments %s\n") fish_md5 $argv + printf (_ "%s: Too many arguments %s\n") fish_md5 $argv >&2 end else echo (md5sum $argv[1] | string split ' ')[1] @@ -17,7 +17,7 @@ function __fish_md5 if test $argv[1] = -s md5 -s $argv[2] else - printf (_ "%s: Too many arguments %s\n") fish_md5 $argv + printf (_ "%s: Too many arguments %s\n") fish_md5 $argv >&2 end else md5 -q $argv[1] diff --git a/share/functions/__fish_print_help.fish b/share/functions/__fish_print_help.fish index ebd89685c..d37b1765e 100644 --- a/share/functions/__fish_print_help.fish +++ b/share/functions/__fish_print_help.fish @@ -37,7 +37,7 @@ function __fish_print_help --description "Print help message for the specified f set -a format -rLL={$cols}n end else - echo fish: (_ "Cannot format help; no parser found") + echo fish: (_ "Cannot format help; no parser found") >&2 return 1 end diff --git a/share/functions/__fish_shared_key_bindings.fish b/share/functions/__fish_shared_key_bindings.fish index ebab94dae..20bb31e6e 100644 --- a/share/functions/__fish_shared_key_bindings.fish +++ b/share/functions/__fish_shared_key_bindings.fish @@ -5,7 +5,7 @@ function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mod if contains -- -h $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 end diff --git a/share/functions/_validate_int.fish b/share/functions/_validate_int.fish index 629cf4c73..dd91b7c40 100644 --- a/share/functions/_validate_int.fish +++ b/share/functions/_validate_int.fish @@ -10,21 +10,21 @@ function _validate_int --no-scope-shadowing if not string match -qr '^-?\d+$' -- $_flag_value 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 end if set -q _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") - printf $msg $_argparse_cmd $_flag_value $_flag_name $_flag_min + printf $msg $_argparse_cmd $_flag_value $_flag_name $_flag_min >&2 return 1 end if set -q _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") - printf $msg $_argparse_cmd $_flag_value $_flag_name $_flag_max + printf $msg $_argparse_cmd $_flag_value $_flag_name $_flag_max >&2 return 1 end diff --git a/share/functions/cd.fish b/share/functions/cd.fish index bf41f4f3b..7ebe37a7e 100644 --- a/share/functions/cd.fish +++ b/share/functions/cd.fish @@ -5,7 +5,7 @@ function cd --description "Change directory" set -l MAX_DIR_HIST 25 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 end diff --git a/share/functions/cdh.fish b/share/functions/cdh.fish index 82d3d193b..0499877a3 100644 --- a/share/functions/cdh.fish +++ b/share/functions/cdh.fish @@ -34,9 +34,9 @@ function cdh --description "Menu based cd command" set -l dirc (count $uniq_dirs) if test $dirc -gt (count $letters) 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') - printf "$msg\n" $dirc (count $letters) + printf "$msg\n" $dirc (count $letters) >&2 return 1 end @@ -77,11 +77,11 @@ function cdh --description "Menu based cd command" cd $uniq_dirs[$choice] return else - printf "$msg\n" $dirc $choice + printf "$msg\n" $dirc $choice >&2 return 1 end else - printf "$msg\n" $dirc $choice + printf "$msg\n" $dirc $choice >&2 return 1 end end diff --git a/share/functions/fish_update_completions.fish b/share/functions/fish_update_completions.fish index cf0151669..b546a1e79 100644 --- a/share/functions/fish_update_completions.fish +++ b/share/functions/fish_update_completions.fish @@ -5,7 +5,7 @@ function fish_update_completions --description "Update man-page based completion if set -l python (__fish_anypython) $python $update_args else - printf "%s\n" (_ "python executable not found") + printf "%s\n" (_ "python executable not found") >&2 return 1 end end diff --git a/share/functions/fish_vi_key_bindings.fish b/share/functions/fish_vi_key_bindings.fish index 914d47e33..e0f8f6d7b 100644 --- a/share/functions/fish_vi_key_bindings.fish +++ b/share/functions/fish_vi_key_bindings.fish @@ -1,7 +1,7 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' if contains -- -h $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 end diff --git a/share/functions/funced.fish b/share/functions/funced.fish index 1b8282dd2..5fa339115 100644 --- a/share/functions/funced.fish +++ b/share/functions/funced.fish @@ -54,7 +54,7 @@ function funced --description 'Edit function definition' set -l editor_cmd echo $editor | read -ta editor_cmd 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 end diff --git a/share/functions/help.fish b/share/functions/help.fish index 1d2fecf15..90c962363 100644 --- a/share/functions/help.fish +++ b/share/functions/help.fish @@ -13,7 +13,7 @@ function help --description 'Show help for the fish shell' if string match -q string $argv[1] set fish_help_item (string join '-' $argv[1] $argv[2]) else - echo "help: Expected at most 1 args, got 2" + echo "help: Expected at most 1 args, got 2" >&2 return 1 end end @@ -93,8 +93,8 @@ function help --description 'Show help for the fish shell' end if not set -q fish_browser[1] - printf (_ '%s: Could not find a web browser.\n') help - printf (_ 'Please try `BROWSER=some_browser help`, `man fish-doc`, or `man fish-tutorial`.\n\n') + 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') >&2 return 1 end diff --git a/share/functions/nextd.fish b/share/functions/nextd.fish index bee91c0c0..9ed623ae1 100644 --- a/share/functions/nextd.fish +++ b/share/functions/nextd.fish @@ -13,7 +13,7 @@ function nextd --description "Move forward in the directory history" if test $argv[1] -ge 0 2>/dev/null set times $argv[1] 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 end end diff --git a/share/functions/open.fish b/share/functions/open.fish index 565bd8496..442bdf568 100644 --- a/share/functions/open.fish +++ b/share/functions/open.fish @@ -14,7 +14,7 @@ if not command -sq open end 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 end @@ -34,7 +34,7 @@ if not command -sq open disown $last_pid 2>/dev/null end 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 diff --git a/share/functions/prevd.fish b/share/functions/prevd.fish index a708909df..0c3a6f25b 100644 --- a/share/functions/prevd.fish +++ b/share/functions/prevd.fish @@ -13,7 +13,7 @@ function prevd --description "Move back in the directory history" if test $argv[1] -ge 0 2>/dev/null set times $argv[1] 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 end end diff --git a/share/functions/pushd.fish b/share/functions/pushd.fish index 90a04ef8d..501a1c650 100644 --- a/share/functions/pushd.fish +++ b/share/functions/pushd.fish @@ -25,7 +25,7 @@ function pushd --description 'Push directory to stack' if not set -q argv[1] # check that the stack isn't empty if not set -q dirstack[1] - echo "pushd: no other directory" + echo "pushd: no other directory" >&2 return 1 end @@ -48,7 +48,7 @@ function pushd --description 'Push directory to stack' if test -n "$rot_r" # check the rotation in range 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 end @@ -57,7 +57,7 @@ function pushd --description 'Push directory to stack' # check the rotation in range 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 else # rotate stack unless rot_l is 0 diff --git a/share/functions/realpath.fish b/share/functions/realpath.fish index 95c3ab395..3a08cce8d 100644 --- a/share/functions/realpath.fish +++ b/share/functions/realpath.fish @@ -49,7 +49,7 @@ function realpath -d "return an absolute path without symlinks" end 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 end diff --git a/share/functions/seq.fish b/share/functions/seq.fish index f91ffdc01..8a2ebc936 100644 --- a/share/functions/seq.fish +++ b/share/functions/seq.fish @@ -36,13 +36,13 @@ if not command -sq seq set step $argv[2] set to $argv[3] 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 end for i in $from $step $to 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 end end diff --git a/share/functions/vared.fish b/share/functions/vared.fish index 402337347..c6cadcd95 100644 --- a/share/functions/vared.fish +++ b/share/functions/vared.fish @@ -12,7 +12,7 @@ function vared --description "Edit variable value" return 0 case '-*' - printf (_ "%s: Unknown option %s\n") vared $argv + printf (_ "%s: Unknown option %s\n") vared $argv >&2 return 1 case '*' @@ -30,10 +30,10 @@ function vared --description "Edit variable value" -c "$$argv" \ $argv 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 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