mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-17 02:02:48 +08:00
abbr: Erase the old universal variable with abbr --erase
This means cleaning out old universal variables is now just: ```fish abbr --erase (abbr --list) ``` which makes upgrading much easier. Note that this erases the currently defined variable and/or any universal. It doesn't stop at the former because that makes it *easy* to remove the universals (no running `abbr --erase` twice), and it doesn't care about globals because, well, they would be gone on restart anyway. Fixes #9468.
This commit is contained in:
parent
27952db9f7
commit
572a568268
|
@ -22,6 +22,7 @@
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
#include "../env.h"
|
#include "../env.h"
|
||||||
#include "../io.h"
|
#include "../io.h"
|
||||||
|
#include "../parser.h"
|
||||||
#include "../re.h"
|
#include "../re.h"
|
||||||
#include "../wcstringutil.h"
|
#include "../wcstringutil.h"
|
||||||
#include "../wgetopt.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.
|
// 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()) {
|
if (opts.args.empty()) {
|
||||||
// This has historically been a silent failure.
|
// This has historically been a silent failure.
|
||||||
return STATUS_CMD_ERROR;
|
return STATUS_CMD_ERROR;
|
||||||
|
@ -282,6 +283,14 @@ static int abbr_erase(const abbr_options_t &opts, io_streams_t &) {
|
||||||
if (!abbrs->erase(arg)) {
|
if (!abbrs->erase(arg)) {
|
||||||
result = ENV_NOT_FOUND;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -410,7 +419,7 @@ maybe_t<int> builtin_abbr(parser_t &parser, io_streams_t &streams, const wchar_t
|
||||||
if (opts.show) return abbr_show(opts, streams);
|
if (opts.show) return abbr_show(opts, streams);
|
||||||
if (opts.list) return abbr_list(opts, streams);
|
if (opts.list) return abbr_list(opts, streams);
|
||||||
if (opts.rename) return abbr_rename(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);
|
if (opts.query) return abbr_query(opts, streams);
|
||||||
|
|
||||||
// validate() should error or ensure at least one path is set.
|
// validate() should error or ensure at least one path is set.
|
||||||
|
|
|
@ -170,6 +170,16 @@ abbr --show
|
||||||
# CHECK: abbr -a -- nonregex_name foo
|
# CHECK: abbr -a -- nonregex_name foo
|
||||||
# CHECK: abbr -a --regex 'A[0-9]B' -- regex_name bar
|
# CHECK: abbr -a --regex 'A[0-9]B' -- regex_name bar
|
||||||
# CHECK: abbr -a --position anywhere --function replace_history -- !!
|
# 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 --erase (abbr --list)
|
||||||
|
|
||||||
abbr --add bogus --position never stuff
|
abbr --add bogus --position never stuff
|
||||||
|
|
Loading…
Reference in New Issue
Block a user