Skip to content

Commit

Permalink
refactor(aliases): rename long option 'output-aliases'
Browse files Browse the repository at this point in the history
  • Loading branch information
olets committed Feb 3, 2020
1 parent 2e191d1 commit 6b922c2
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 80 deletions.
58 changes: 29 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ Default is universal.

```
abbr [(--add | -a)
| (--create-aliases | -c)
| (--erase | -e)
| (--erase-all-globals | -E)
| (--expand | -x)
| (--git-populate | -i)
| (--global | -g)
| (--help | -h)
| (--git-populate | -i)
| (--list | -l)
| (--output-aliases | -o)
| (--populate | -p)
| (--rename | -r)
| (--show | -s)
Expand Down Expand Up @@ -188,33 +188,6 @@ abbr 'a||b' c # will error

Abbreviations can also be manually added to the `ZSH_ABBR_UNIVERSALS_FILE`.

#### Create Aliases

```
abbr (--create-aliases | -c) [DESTINATION]
```

Export abbreviations as aliases declarations. To export global abbreviations, use **--global**. Othewise, or if the **--universal** scope is used, universal abbreviations are exported.

```shell
% abbr --add gcm git checkout master
% abbr --add --global g git
```
```shell
% abbr --create-aliases
alias -g gcm='git checkout master'
```
```shell
% abbr --create-aliases --global
alias -g g='git'
```
```shell
% abbr --create-aliases ~/.zshrc
% cat ~/.zshrc
# -- snip --
alias -g g='git'
```

#### Erase

```
Expand Down Expand Up @@ -306,6 +279,33 @@ a
b
```

#### Output Aliases

```
abbr (--output-aliases | -o) [DESTINATION]
```

Export abbreviations as aliases declarations. To export global abbreviations, use **--global**. Othewise, or if the **--universal** scope is used, universal abbreviations are exported.

```shell
% abbr --add gcm git checkout master
% abbr --add --global g git
```
```shell
% abbr --output-aliases
alias -g gcm='git checkout master'
```
```shell
% abbr --output-aliases --global
alias -g g='git'
```
```shell
% abbr --output-aliases ~/.zshrc
% cat ~/.zshrc
# -- snip --
alias -g g='git'
```

#### Populate

```
Expand Down
102 changes: 51 additions & 51 deletions zsh-abbr.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ _zsh_abbr() {
local action_set=false
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
local opt_global=false
local opt_list=false
local opt_output_aliases=false
local opt_populate=false
local opt_rename=false
local opt_show=false
local opt_populate=false
local opt_universal=false
local opt_print_version=false
local release_date="January 19 2020"
Expand All @@ -45,7 +45,7 @@ _zsh_abbr() {
${text_bold}Synopsis${text_reset}
${text_bold}abbr${text_reset} --add|-a [SCOPE] ABBREVIATION EXPANSION
${text_bold}abbr${text_reset} --create-aliases|-c [SCOPE] [DESTINATION]
${text_bold}abbr${text_reset} --output-aliases|-o [SCOPE] [DESTINATION]
${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]
Expand Down Expand Up @@ -73,12 +73,6 @@ _zsh_abbr() {
o --add ABBREVIATION EXPANSION or -a ABBREVIATION EXPANSION Adds a new
abbreviation, causing ABBREVIATION to be expanded to EXPANSION.
o --create-aliases [-g] [DESTINATION_FILE] or -c [-g] [DESTINATION_FILE]
Outputs a list of alias command for universal abbreviations, suitable
for pasting or piping to whereever you keep aliases. Add -g to output
alias commands for global abbreviations. If a DESTINATION_FILE is
provided, the commands will be appended to it.
o --erase ABBREVIATION or -e ABBREVIATION Erases the
abbreviation ABBREVIATION.
Expand All @@ -95,6 +89,12 @@ _zsh_abbr() {
o --list -l Lists all ABBREVIATIONs.
o --output-aliases [-g] [DESTINATION_FILE] or -o [-g] [DESTINATION_FILE]
Outputs a list of alias command for universal abbreviations, suitable
for pasting or piping to whereever you keep aliases. Add -g to output
alias commands for global abbreviations. If a DESTINATION_FILE is
provided, the commands will be appended to it.
o --populate or -p Adds abbreviations for all aliases.
o --rename OLD_ABBREVIATION NEW_ABBREVIATION
Expand All @@ -106,7 +106,7 @@ _zsh_abbr() {
o --version or -v Show the current version.
In addition, when adding abbreviations, creating aliases, erasing,
In addition, when adding abbreviations, erasing, outputting aliases,
[git] populating, or renaming use
o --global or -g to create a global abbreviation, available only in the
Expand Down Expand Up @@ -137,20 +137,20 @@ _zsh_abbr() {
Add a new abbreviation where l will be replaced with less universal so
all shells. Note that you omit the -U since it is the default.
${text_bold}abbr${text_reset} -c -g
${text_bold}abbr${text_reset} --create-aliases -global
${text_bold}abbr${text_reset} -o -g
${text_bold}abbr${text_reset} --output-aliases -global
Output alias declaration commands for each *global* abbreviation.
Output lines look like alias -g <ABBREVIATION>='<EXPANSION>'
${text_bold}abbr${text_reset} -c
${text_bold}abbr${text_reset} --create-aliases
${text_bold}abbr${text_reset} -o
${text_bold}abbr${text_reset} --output-aliases
Output alias declaration commands for each *universal* abbreviation.
Output lines look like alias -g <ABBREVIATION>='<EXPANSION>'
${text_bold}abbr${text_reset} -c ~/aliases
${text_bold}abbr${text_reset} --create-aliases ~/aliases
${text_bold}abbr${text_reset} -o ~/aliases
${text_bold}abbr${text_reset} --output-aliases ~/aliases
Add alias definitions to ~/aliases
Expand Down Expand Up @@ -188,7 +188,7 @@ _zsh_abbr() {
the scope. If you want it to be visible only to the current shell
use the -g flag.
The options add, create-aliases, erase, expand, git-populate, list,
The options add, output-aliases, erase, expand, git-populate, list,
populate, rename, and show are mutually exclusive, as are the global
and universal scopes.
Expand All @@ -204,32 +204,6 @@ _zsh_abbr() {
util_add $* # must not be quoted
}

function create_aliases() {
local source
local alias_definition

if [ $# -gt 1 ]; then
util_error " create-aliases: Unexpected argument"
return
fi

if $opt_global; then
source=ZSH_ABBR_GLOBALS
else
source=ZSH_ABBR_UNIVERSALS
fi

for abbreviation expansion in ${(kv)${(P)source}}; do
alias_definition="alias -g $abbreviation='$expansion'"

if [ $# -gt 0 ]; then
echo "$alias_definition" >> "$1"
else
print "$alias_definition"
fi
done
}

function erase() {
if [ $# -gt 1 ]; then
util_error " erase: Expected one argument"
Expand Down Expand Up @@ -309,6 +283,32 @@ _zsh_abbr() {
print -l ${(k)ZSH_ABBR_GLOBALS}
}

function output_aliases() {
local source
local alias_definition

if [ $# -gt 1 ]; then
util_error " output-aliases: Unexpected argument"
return
fi

if $opt_global; then
source=ZSH_ABBR_GLOBALS
else
source=ZSH_ABBR_UNIVERSALS
fi

for abbreviation expansion in ${(kv)${(P)source}}; do
alias_definition="alias -g $abbreviation='$expansion'"

if [ $# -gt 0 ]; then
echo "$alias_definition" >> "$1"
else
print "$alias_definition"
fi
done
}

function populate() {
if [ $# -gt 0 ]; then
util_error " populate: Unexpected argument"
Expand Down Expand Up @@ -487,13 +487,6 @@ _zsh_abbr() {
opt_add=true
((number_opts++))
;;
"--create-aliases"|\
"-c")
[ "$action_set" = true ] && util_bad_options
action_set=true
opt_create_aliases=true
((number_opts++))
;;
"--erase"|\
"-e")
[ "$action_set" = true ] && util_bad_options
Expand Down Expand Up @@ -541,6 +534,13 @@ _zsh_abbr() {
opt_list=true
((number_opts++))
;;
"--output-aliases"|\
"-o")
[ "$action_set" = true ] && util_bad_options
action_set=true
opt_output_aliases=true
((number_opts++))
;;
"--populate"|\
"-p")
[ "$action_set" = true ] && util_bad_options
Expand Down Expand Up @@ -623,12 +623,12 @@ _zsh_abbr() {
fi
} always {
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"
unfunction -m "output_aliases"
unfunction -m "populate"
unfunction -m "print_version"
unfunction -m "rename"
Expand Down

0 comments on commit 6b922c2

Please sign in to comment.