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.
This commit is contained in:
Fabian Boehm 2022-12-13 19:38:58 +01:00
parent aca8c52660
commit 30a37d9433
2 changed files with 6 additions and 6 deletions

View file

@ -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<int> 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;
}
}

View file

@ -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