diff --git a/src/builtins/abbr.cpp b/src/builtins/abbr.cpp index 323716263..bb8fc204d 100644 --- a/src/builtins/abbr.cpp +++ b/src/builtins/abbr.cpp @@ -22,6 +22,7 @@ #include "../common.h" #include "../env.h" #include "../io.h" +#include "../parser.h" #include "../re.h" #include "../wcstringutil.h" #include "../wgetopt.h" @@ -269,7 +270,7 @@ static int abbr_add(const abbr_options_t &opts, io_streams_t &streams) { } // Erase the named abbreviations. -static int abbr_erase(const abbr_options_t &opts, io_streams_t &) { +static int abbr_erase(const abbr_options_t &opts, parser_t &parser, io_streams_t &) { if (opts.args.empty()) { // This has historically been a silent failure. return STATUS_CMD_ERROR; @@ -282,6 +283,14 @@ static int abbr_erase(const abbr_options_t &opts, io_streams_t &) { if (!abbrs->erase(arg)) { result = ENV_NOT_FOUND; } + // Erase the old uvar - this makes `abbr -e` work. + wcstring esc_src = escape_string(arg, 0, STRING_STYLE_VAR); + if (!esc_src.empty()) { + wcstring var_name = L"_fish_abbr_" + esc_src; + auto ret = parser.vars().remove(var_name, ENV_UNIVERSAL); + if (ret == ENV_OK) result = STATUS_CMD_OK; + } + } return result; } @@ -410,7 +419,7 @@ maybe_t builtin_abbr(parser_t &parser, io_streams_t &streams, const wchar_t if (opts.show) return abbr_show(opts, streams); if (opts.list) return abbr_list(opts, streams); if (opts.rename) return abbr_rename(opts, streams); - if (opts.erase) return abbr_erase(opts, streams); + if (opts.erase) return abbr_erase(opts, parser, streams); if (opts.query) return abbr_query(opts, streams); // validate() should error or ensure at least one path is set. diff --git a/tests/checks/abbr.fish b/tests/checks/abbr.fish index ea7b8530c..1d021e9d0 100644 --- a/tests/checks/abbr.fish +++ b/tests/checks/abbr.fish @@ -170,6 +170,16 @@ abbr --show # CHECK: abbr -a -- nonregex_name foo # CHECK: abbr -a --regex 'A[0-9]B' -- regex_name bar # CHECK: abbr -a --position anywhere --function replace_history -- !! + +# Confirm that this erases the old uvar +# (slightly cheating since we haven't imported it as an abbr, +# but that's okay) +abbr --erase cuckoo +echo erase $status +# CHECK: erase 0 +set --show _fish_abbr_cuckoo +# Nothing + abbr --erase (abbr --list) abbr --add bogus --position never stuff