From d8dbb9b259ca7c927303a91c115e144ab712d6df Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 10 Dec 2022 14:16:26 -0800 Subject: [PATCH] Switch abbreviation '-r' flag from --rename to --regex This will be the more common option and provides consistency with `string`. --- CHANGELOG.rst | 1 + doc_src/cmds/abbr.rst | 9 ++++----- src/builtins/abbr.cpp | 29 +++++++++++------------------ tests/checks/abbr.fish | 12 ++++++------ 4 files changed, 22 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9bc5ff1c2..1d8157851 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -44,6 +44,7 @@ Deprecations and removed features - The ``fish_git_prompt`` will now only turn on features if the corresponding boolean variable has been set to a true value (of "1", "yes" or "true") instead of just checking if it is defined. This allows specifically turning features *off* without having to erase variables, e.g. via universal variables. If you have defined a variable to a different value and expect it to count as true, you need to change it (:issue:`9274`). For example, ``set -g __fish_git_prompt_show_informative_status 0`` previously would have enabled informative status (because any value would have done so), now it turns it off. - Abbreviations are no longer stored in universal variables. Existing universal abbreviations are still imported, but new abbreviations should be added to ``config.fish``. +- The short option ``-r`` for abbreviations has changed from ``rename`` to ``regex``, for consistency with ``string``. Scripting improvements ---------------------- diff --git a/doc_src/cmds/abbr.rst b/doc_src/cmds/abbr.rst index 00a13e672..6431251fa 100644 --- a/doc_src/cmds/abbr.rst +++ b/doc_src/cmds/abbr.rst @@ -8,7 +8,7 @@ Synopsis .. synopsis:: - abbr --add NAME [--position command | anywhere] [--regex PATTERN] + abbr --add NAME [--position command | anywhere] [-r | --regex PATTERN] [--set-cursor[=MARKER]] [-f | --function] EXPANSION abbr --erase NAME ... @@ -37,9 +37,8 @@ Abbreviations may be added to :ref:`config.fish `. Abbreviations .. synopsis:: - abbr [-a | --add] NAME [--position command | anywhere] [--regex PATTERN] - [--set-cursor[=MARKER]] - [-f | --function] EXPANSION + abbr [-a | --add] NAME [--position command | anywhere] [-r | --regex PATTERN] + [--set-cursor[=MARKER]] [-f | --function] EXPANSION ``abbr --add`` creates a new abbreviation. With no other options, the string **NAME** is replaced by **EXPANSION**. @@ -104,7 +103,7 @@ Other subcommands :: - abbr [-r | --rename] OLD_NAME NEW_NAME + abbr --rename OLD_NAME NEW_NAME Renames an abbreviation, from *OLD_NAME* to *NEW_NAME* diff --git a/src/builtins/abbr.cpp b/src/builtins/abbr.cpp index f28bdcbdf..ce234f1b6 100644 --- a/src/builtins/abbr.cpp +++ b/src/builtins/abbr.cpp @@ -277,27 +277,20 @@ maybe_t builtin_abbr(parser_t &parser, io_streams_t &streams, const wchar_t const wchar_t *cmd = argv[0]; abbr_options_t opts; // Note 1 is returned by wgetopt to indicate a non-option argument. - enum { NON_OPTION_ARGUMENT = 1, REGEX_SHORT, SET_CURSOR_SHORT }; + enum { NON_OPTION_ARGUMENT = 1, SET_CURSOR_SHORT, RENAME_SHORT }; // Note the leading '-' causes wgetopter to return arguments in order, instead of permuting // them. We need this behavior for compatibility with pre-builtin abbreviations where options // could be given literally, for example `abbr e emacs -nw`. - static const wchar_t *const short_options = L"-afrseqgUh"; + static const wchar_t *const short_options = L"-afr:seqgUh"; static const struct woption long_options[] = { - {L"add", no_argument, 'a'}, - {L"position", required_argument, 'p'}, - {L"regex", required_argument, REGEX_SHORT}, - {L"set-cursor", optional_argument, SET_CURSOR_SHORT}, - {L"function", no_argument, 'f'}, - {L"rename", no_argument, 'r'}, - {L"erase", no_argument, 'e'}, - {L"query", no_argument, 'q'}, - {L"show", no_argument, 's'}, - {L"list", no_argument, 'l'}, - {L"global", no_argument, 'g'}, - {L"universal", no_argument, 'U'}, - {L"help", no_argument, 'h'}, - {}}; + {L"add", no_argument, 'a'}, {L"position", required_argument, 'p'}, + {L"regex", required_argument, 'r'}, {L"set-cursor", optional_argument, SET_CURSOR_SHORT}, + {L"function", no_argument, 'f'}, {L"rename", no_argument, RENAME_SHORT}, + {L"erase", no_argument, 'e'}, {L"query", no_argument, 'q'}, + {L"show", no_argument, 's'}, {L"list", no_argument, 'l'}, + {L"global", no_argument, 'g'}, {L"universal", no_argument, 'U'}, + {L"help", no_argument, 'h'}, {}}; int argc = builtin_count_args(argv); int opt; @@ -337,7 +330,7 @@ maybe_t builtin_abbr(parser_t &parser, io_streams_t &streams, const wchar_t } break; } - case REGEX_SHORT: { + case 'r': { if (opts.regex_pattern.has_value()) { streams.err.append_format(_(L"%ls: Cannot specify multiple regex patterns\n"), CMD); @@ -359,7 +352,7 @@ maybe_t builtin_abbr(parser_t &parser, io_streams_t &streams, const wchar_t case 'f': opts.function = true; break; - case 'r': + case RENAME_SHORT: opts.rename = true; break; case 'e': diff --git a/tests/checks/abbr.fish b/tests/checks/abbr.fish index e539cb4db..b5a348c28 100644 --- a/tests/checks/abbr.fish +++ b/tests/checks/abbr.fish @@ -56,30 +56,30 @@ abbr | grep 'a b c' # Test renaming abbr __abbr4 omega abbr | grep __abbr5 -abbr -r __abbr4 __abbr5 +abbr --rename __abbr4 __abbr5 abbr | grep __abbr5 # CHECK: abbr -a -- __abbr5 omega abbr -e __abbr5 abbr | grep __abbr4 # Test renaming a nonexistent abbreviation -abbr -r __abbr6 __abbr +abbr --rename __abbr6 __abbr # CHECKERR: abbr --rename: No abbreviation named __abbr6 # Test renaming to a abbreviation with spaces abbr __abbr4 omega -abbr -r __abbr4 "g h i" +abbr --rename __abbr4 "g h i" # CHECKERR: abbr --rename: Abbreviation 'g h i' cannot have spaces in the word abbr -e __abbr4 # Test renaming without arguments abbr __abbr7 omega -abbr -r __abbr7 +abbr --rename __abbr7 # CHECKERR: abbr --rename: Requires exactly two arguments # Test renaming with too many arguments abbr __abbr8 omega -abbr -r __abbr8 __abbr9 __abbr10 +abbr --rename __abbr8 __abbr9 __abbr10 # CHECKERR: abbr --rename: Requires exactly two arguments abbr | grep __abbr8 abbr | grep __abbr9 @@ -89,7 +89,7 @@ abbr | grep __abbr10 # Test renaming to existing abbreviation abbr __abbr11 omega11 abbr __abbr12 omega12 -abbr -r __abbr11 __abbr12 +abbr --rename __abbr11 __abbr12 # CHECKERR: abbr --rename: Abbreviation __abbr12 already exists, cannot rename __abbr11 abbr __abbr-with-dashes omega