From 30a37d9433b938b22a8c5b3538b6bf1e83f1757c Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Tue, 13 Dec 2022 19:38:58 +0100 Subject: [PATCH] abbr: Make show output actually work This would print ``` abbr -a -- dotdot --regex ^\\.\\.+\$ --function multicd ``` which expands "dotdot" to "--regex ^\\.\\.+\$...". Instead, we move the name to right before the replacement, and move the `--` before that: ``` abbr -a --regex ^\\.\\.+\$ --function -- dotdot multicd ``` It might be possible to improve that, but this at least round-trips. --- src/builtins/abbr.cpp | 10 +++++----- tests/checks/abbr.fish | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/builtins/abbr.cpp b/src/builtins/abbr.cpp index b7349fd82..31f10264c 100644 --- a/src/builtins/abbr.cpp +++ b/src/builtins/abbr.cpp @@ -99,10 +99,6 @@ static int abbr_show(const abbr_options_t &, io_streams_t &streams) { comps.clear(); comps.push_back(L"abbr -a"); if (abbr.from_universal) comps.push_back(L"-U"); - comps.push_back(L"--"); - // Literal abbreviations have the name and key as the same. - // Regex abbreviations have a pattern separate from the name. - comps.push_back(escape_string(abbr.name)); if (abbr.is_regex()) { comps.push_back(L"--regex"); comps.push_back(escape_string(abbr.key)); @@ -113,6 +109,10 @@ static int abbr_show(const abbr_options_t &, io_streams_t &streams) { if (abbr.replacement_is_function) { comps.push_back(L"--function"); } + comps.push_back(L"--"); + // Literal abbreviations have the name and key as the same. + // Regex abbreviations have a pattern separate from the name. + comps.push_back(escape_string(abbr.name)); comps.push_back(escape_string(abbr.replacement)); wcstring result = join_strings(comps, L' '); result.push_back(L'\n'); @@ -397,4 +397,4 @@ maybe_t builtin_abbr(parser_t &parser, io_streams_t &streams, const wchar_t // validate() should error or ensure at least one path is set. DIE("unreachable"); return STATUS_INVALID_ARGS; -} \ No newline at end of file +} diff --git a/tests/checks/abbr.fish b/tests/checks/abbr.fish index b5a348c28..17612d53b 100644 --- a/tests/checks/abbr.fish +++ b/tests/checks/abbr.fish @@ -158,7 +158,7 @@ abbr --add nonregex_name foo abbr --add regex_name --regex 'A[0-9]B' bar abbr --show # CHECK: abbr -a -- nonregex_name foo -# CHECK: abbr -a -- regex_name --regex 'A[0-9]B' bar +# CHECK: abbr -a --regex 'A[0-9]B' -- regex_name bar abbr --erase (abbr --list) abbr --add bogus --position never stuff