From 8dcde27e0babee857eb307b88feb97e6d3190df0 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Thu, 21 Nov 2024 18:42:13 +0100 Subject: [PATCH] functions/history: Put back some checks for clear{,-session} Mostly we pass on the options - otherwise they would be ignored. For `clear`, we do need the full checks, because that will prompt *before* running the builtin. But this makes it easier to eventually move that logic into the builtin --- share/functions/history.fish | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/share/functions/history.fish b/share/functions/history.fish index fecb9fec3..011bbc87f 100644 --- a/share/functions/history.fish +++ b/share/functions/history.fish @@ -176,28 +176,38 @@ function history --description "display or manipulate interactive command histor end case save # save our interactive command history to the persistent history - builtin history save -- $argv + builtin history save $search_mode $show_time $max_count $_flag_case_sensitive $_flag_reverse $_flag_null -- $argv case merge # merge the persistent interactive command history with our history - builtin history merge -- $argv + builtin history merge $search_mode $show_time $max_count $_flag_case_sensitive $_flag_reverse $_flag_null -- $argv case clear # clear the interactive command history + if test -n "$search_mode" + or set -q show_time[1] + printf (_ "%ls: %ls: subcommand takes no options\n") history $hist_cmd >&2 + return 1 + end + if set -q argv[1] + printf (_ "%ls: %ls: expected %d arguments; got %d\n") history $hist_cmd 0 (count $argv) >&2 + return 1 + end + printf (_ "If you enter 'yes' your entire interactive command history will be erased\n") read --local --prompt "echo 'Are you sure you want to clear history? (yes/no) '" choice if test "$choice" = yes - builtin history clear -- $argv + builtin history clear $search_mode $show_time $max_count $_flag_case_sensitive $_flag_reverse $_flag_null -- $argv and printf (_ "Command history cleared!\n") else printf (_ "You did not say 'yes' so I will not clear your command history\n") end case clear-session # clears only session - builtin history clear-session -- $argv - printf (_ "Command history for session cleared!\n") + builtin history clear-session $search_mode $show_time $max_count $_flag_case_sensitive $_flag_reverse $_flag_null -- $argv + and printf (_ "Command history for session cleared!\n") case append set -l newitem $argv if not set -q argv[1] read -P "Command: " newitem end - builtin history append -- $newitem + builtin history append $search_mode $show_time $max_count $_flag_case_sensitive $_flag_reverse $_flag_null -- $newitem case '*' printf "%ls: unexpected subcommand '%ls'\n" $cmd $hist_cmd return 2