From 6d18f57e9675a1eca0dcf07e20ece4f6aa2a375d Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 14 Jan 2025 09:19:01 +0100 Subject: [PATCH] Make ! a builtin too, fixing "! -h" UnLike other aliases (":.["), ! is special in the grammar but in the few cases like "! -h" where we parse it as decorated statement they are equals. Add it to the built in list, so the help argument works. It can still be overridden, so this should not break anything. --- share/functions/__fish_print_help.fish | 2 ++ share/functions/help.fish | 2 ++ src/builtins/shared.rs | 5 +++++ tests/checks/not.fish | 11 +++++++++++ 4 files changed, 20 insertions(+) diff --git a/share/functions/__fish_print_help.fish b/share/functions/__fish_print_help.fish index 352070d6d..a4888898f 100644 --- a/share/functions/__fish_print_help.fish +++ b/share/functions/__fish_print_help.fish @@ -1,5 +1,7 @@ function __fish_print_help --description "Print help message for the specified fish function or builtin" --argument-names item error_message switch $item + case ! + set item not case . set item source case : diff --git a/share/functions/help.fish b/share/functions/help.fish index 361e31b84..ff61143a2 100644 --- a/share/functions/help.fish +++ b/share/functions/help.fish @@ -129,6 +129,8 @@ function help --description 'Show help for the fish shell' set -l fish_help_page switch "$fish_help_item" + case "!" + set fish_help_page "cmds/not.html" case "." set fish_help_page "cmds/source.html" case ":" diff --git a/src/builtins/shared.rs b/src/builtins/shared.rs index 213b815f7..f80935333 100644 --- a/src/builtins/shared.rs +++ b/src/builtins/shared.rs @@ -113,6 +113,10 @@ struct BuiltinData { // Functions that are bound to builtin_generic are handled directly by the parser. // NOTE: These must be kept in sorted order! const BUILTIN_DATAS: &[BuiltinData] = &[ + BuiltinData { + name: L!("!"), + func: builtin_generic, + }, BuiltinData { name: L!("."), func: source::source, @@ -471,6 +475,7 @@ pub fn builtin_get_names() -> impl Iterator { /// Return a one-line description of the specified builtin. pub fn builtin_get_desc(name: &wstr) -> Option<&'static wstr> { let desc = match name { + _ if name == "!" => wgettext!("Negate exit status of job"), _ if name == "." => wgettext!("Evaluate contents of file"), _ if name == ":" => wgettext!("Return a successful result"), _ if name == "[" => wgettext!("Test a condition"), // ] diff --git a/tests/checks/not.fish b/tests/checks/not.fish index 77a03c419..111e434f8 100644 --- a/tests/checks/not.fish +++ b/tests/checks/not.fish @@ -8,3 +8,14 @@ echo $status not not sh -c 'exit 34' echo $status # CHECK: 34 + +! -h +# CHECKERR: fish: !: missing man page +# CHECKERR: Documentation may not be installed. +# CHECKERR: `help !` will show an online version + +function ! + echo overridden! $argv +end +! -h +# CHECK: overridden! -h