From b0c2d083d625e4e7bba8a9c9cf0afd4f96b1aac2 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 8 Apr 2022 16:50:34 +0200 Subject: [PATCH] set: Add special error for `set foo=bar` Fixes #8694 Only for setting, erasing with a value makes no sense. --- src/builtins/set.cpp | 6 ++++++ tests/checks/set.fish | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/builtins/set.cpp b/src/builtins/set.cpp index e4e83fbd0..0f72673d3 100644 --- a/src/builtins/set.cpp +++ b/src/builtins/set.cpp @@ -720,6 +720,12 @@ static int builtin_set_set(const wchar_t *cmd, set_cmd_opts_t &opts, int argc, c // Is the variable valid? if (!valid_var_name(split->varname)) { streams.err.append_format(BUILTIN_ERR_VARNAME, cmd, split->varname.c_str()); + auto pos = split->varname.find(L'='); + if (pos != wcstring::npos) { + streams.err.append_format(L"%ls: Did you mean `set %ls %ls`?", cmd, + escape_string(split->varname.substr(0, pos), ESCAPE_ALL, STRING_STYLE_SCRIPT).c_str(), + escape_string(split->varname.substr(pos + 1), ESCAPE_ALL, STRING_STYLE_SCRIPT).c_str()); + } builtin_print_error_trailer(parser, streams.err, cmd); return STATUS_INVALID_ARGS; } diff --git a/tests/checks/set.fish b/tests/checks/set.fish index d571a4a2a..b06f3030b 100644 --- a/tests/checks/set.fish +++ b/tests/checks/set.fish @@ -770,6 +770,13 @@ set --show "" #CHECKERR: ^ #CHECKERR: (Type 'help set' for related documentation) +set foo="ba nana" +#CHECKERR: set: foo=ba nana: invalid variable name. See `help identifiers` +#CHECKERR: set: Did you mean `set foo 'ba nana'`? +#CHECKERR: {{.*}}set.fish (line {{\d+}}): +#CHECKERR: set foo="ba nana" +#CHECKERR: ^ +#CHECKERR: (Type 'help set' for related documentation) # Test path splitting begin set -l PATH /usr/local/bin:/usr/bin