From bf90f878287fec6bcb397f9a33713d5ac262c9f1 Mon Sep 17 00:00:00 2001 From: Henry Bley-Vroman Date: Mon, 3 Feb 2020 17:41:08 -0500 Subject: [PATCH] refactor(clear globals): rename from 'erase-all-globals' --- README.md | 18 +++++++++--------- zsh-abbr.zsh | 45 +++++++++++++++++++++++---------------------- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 0b0e6b63..40f5fa5c 100644 --- a/README.md +++ b/README.md @@ -133,8 +133,8 @@ Default is universal. ```shell abbr [(--add | -a) + | (--clear-globals | -c) | (--erase | -e) - | (--erase-all-globals | -E) | (--expand | -x) | (--git-populate | -i) | (--global | -g) @@ -188,6 +188,14 @@ abbr 'a||b' c # will error Abbreviations can also be manually added to the `ZSH_ABBR_UNIVERSALS_FILE`. +#### Clear Globals + +```shell +abbr (--clear-globals | -c) +``` + +Erase all global abbreviations. + #### Erase ``` @@ -214,14 +222,6 @@ Already on 'master' Universal abbreviations can also be manually erased from the `ZSH_ABBR_UNIVERSALS_FILE`. -#### Erase All Globals - -```shell -abbr (--erase-all-globals | -E) -``` - -Erase all global abbreviations. - #### Expand ```shell diff --git a/zsh-abbr.zsh b/zsh-abbr.zsh index 884b6205..5c84fab6 100755 --- a/zsh-abbr.zsh +++ b/zsh-abbr.zsh @@ -23,7 +23,7 @@ _zsh_abbr() { local action_set=false local number_opts=0 local opt_add=false - local opt_erase_all_globals=false + local opt_clear_globals=false local opt_erase=false local opt_expand=false local opt_git_populate=false @@ -45,11 +45,12 @@ _zsh_abbr() { ${text_bold}Synopsis${text_reset} ${text_bold}abbr${text_reset} --add|-a [SCOPE] ABBREVIATION EXPANSION - ${text_bold}abbr${text_reset} --output-aliases|-o [SCOPE] [DESTINATION] + ${text_bold}abbr${text_reset} --clear-globals|-c [SCOPE] ABBREVIATION ${text_bold}abbr${text_reset} --erase|-e [SCOPE] ABBREVIATION ${text_bold}abbr${text_reset} --expand|-x ABBREVIATION ${text_bold}abbr${text_reset} --git-populate|-i [SCOPE] ${text_bold}abbr${text_reset} --list|-l + ${text_bold}abbr${text_reset} --output-aliases|-o [SCOPE] [DESTINATION] ${text_bold}abbr${text_reset} --populate|-p [SCOPE] ${text_bold}abbr${text_reset} --rename|-r [SCOPE] OLD_ABBREVIATION NEW ${text_bold}abbr${text_reset} --show|-s @@ -73,11 +74,11 @@ _zsh_abbr() { o --add ABBREVIATION EXPANSION or -a ABBREVIATION EXPANSION Adds a new abbreviation, causing ABBREVIATION to be expanded to EXPANSION. + o --clear-globals or -E Erases all global abbreviations. + o --erase ABBREVIATION or -e ABBREVIATION Erases the abbreviation ABBREVIATION. - o --erase-all-globals or -E Erases all global abbreviations. - o --expand ABBREVIATION or -x ABBREVIATION Returns the abbreviation ABBREVIATION's EXPANSION. @@ -204,6 +205,15 @@ _zsh_abbr() { util_add $* # must not be quoted } + function clear_globals() { + if [ $# -gt 0 ]; then + util_error " clear-globals: Unexpected argument" + return + fi + + ZSH_ABBR_GLOBALS=() + } + function erase() { if [ $# -gt 1 ]; then util_error " erase: Expected one argument" @@ -233,15 +243,6 @@ _zsh_abbr() { fi } - function erase_all_globals() { - if [ $# -gt 0 ]; then - util_error " erase-all-globals: Unexpected argument" - return - fi - - ZSH_ABBR_GLOBALS=() - } - function expand() { if [ $# -ne 1 ]; then printf "expand requires exactly one argument\\n" @@ -512,18 +513,18 @@ _zsh_abbr() { opt_add=true ((number_opts++)) ;; - "--erase"|\ - "-e") + "--clear-globals"|\ + "-c") [ "$action_set" = true ] && util_bad_options action_set=true - opt_erase=true + opt_clear_globals=true ((number_opts++)) ;; - "--erase-all-globals"|\ - "-E") + "--erase"|\ + "-e") [ "$action_set" = true ] && util_bad_options action_set=true - opt_erase_all_globals=true + opt_erase=true ((number_opts++)) ;; "--expand"|\ @@ -622,8 +623,8 @@ _zsh_abbr() { add "$@" elif $opt_create_aliases; then create_aliases "$@" - elif $opt_erase_all_globals; then - erase_all_globals "$@" + elif $opt_clear_globals; then + clear_globals "$@" elif $opt_erase; then erase "$@" elif $opt_expand; then @@ -648,8 +649,8 @@ _zsh_abbr() { fi } always { unfunction -m "add" + unfunction -m "clear-globals" unfunction -m "erase" - unfunction -m "erase-all-globals" unfunction -m "expand" unfunction -m "git_populate" unfunction -m "list"