Skip to content

Commit

Permalink
feat(erase-all-global): new option
Browse files Browse the repository at this point in the history
  • Loading branch information
olets committed Jan 19, 2020
1 parent ad9add4 commit f7b1bee
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ Default is universal.
abbr [(--add | -a)
| (--create-aliases | -c)
| (--erase | -e)
| (--erase-all-globals | -E)
| (--expand | -x)
| (--global | -g)
| (--help | -h)
Expand Down Expand Up @@ -235,7 +236,15 @@ gimme cookie monster
Already on 'master'
```

Abbreviations can also be manually erased from the `ZSH_ABBR_UNIVERSALS_FILE`.
Universal abbreviations can also be manually erased from the `ZSH_ABBR_UNIVERSALS_FILE`.

#### Erase All Globals

```
abbr (--erase-all-globals | -E)
```

Erase all global abbreviations.

#### Expand

Expand Down
22 changes: 22 additions & 0 deletions zsh-abbr.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function _zsh_abbr() {
local number_opts=0
local opt_add=false
local opt_create_aliases=false
local opt_erase_all_globals=false
local opt_erase=false
local opt_expand=false
local opt_git_populate=false
Expand Down Expand Up @@ -80,6 +81,8 @@ function _zsh_abbr() {
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.
Expand Down Expand Up @@ -252,6 +255,15 @@ function _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"
Expand Down Expand Up @@ -480,6 +492,13 @@ function _zsh_abbr() {
opt_erase=true
((number_opts++))
;;
"--erase-all-globals"|\
"-E")
[ "$action_set" = true ] && util_bad_options
action_set=true
opt_erase_all_globals=true
((number_opts++))
;;
"--expand"|\
"-x")
[ "$action_set" = true ] && util_bad_options
Expand Down Expand Up @@ -566,6 +585,8 @@ function _zsh_abbr() {
add "$@"
elif $opt_create_aliases; then
create_aliases "$@"
elif $opt_erase_all_globals; then
erase_all_globals "$@"
elif $opt_erase; then
erase "$@"
elif $opt_expand; then
Expand All @@ -592,6 +613,7 @@ function _zsh_abbr() {
unfunction -m "add"
unfunction -m "create_aliases"
unfunction -m "erase"
unfunction -m "erase-all-globals"
unfunction -m "expand"
unfunction -m "git_populate"
unfunction -m "list"
Expand Down

0 comments on commit f7b1bee

Please sign in to comment.