Skip to content

Commit

Permalink
feat(list commands): rename from show
Browse files Browse the repository at this point in the history
  • Loading branch information
olets committed Mar 7, 2020
1 parent 25fae62 commit 45b9a69
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ Default is user.
| --import-fish [(--global | -g)] [--dry-run] arg
| --import-git-aliases [--dry-run]
| (--list | -l)
| (--list-commands | -L | -s) [(--global | -g)]
| (--rename | -r ) [(--global | -g)] [--dry-run] args
| (--show | -s)
]
```

`zsh-abbr` has options to add, rename, and erase abbreviations; to add abbreviations for every alias or Git alias; to list the available abbreviations with or without their expansions; and to create aliases from abbreviations.

`abbr` with no arguments is shorthand for `abbr --show`. `abbr ...` with arguments and no flags is shorthand for `abbr --add ...`.
`abbr` with no arguments is shorthand for `abbr --list-commands`. `abbr ...` with arguments and no flags is shorthand for `abbr --add ...`.

#### Add

Expand Down Expand Up @@ -431,22 +431,22 @@ Use `--dry-run` to see what would result, without making any actual changes..
Abbreviations can also be manually renamed in the `ZSH_USER_ABBREVIATIONS_PATH`.
#### Show
#### List Commands
```shell
abbr [(--show|-s)]
abbr [(--list-commands | -L | -s)] [(--global | -g)]
```
Show all the abbreviations available in the current session, along with their expansions. _**Show** does not take a scope._ Session abbreviations are marked `-S` and follow user abbreviations.
List all the abbreviations available in the current session as commands. _**Show** does not take a scope._ Session abbreviations are marked `-S` and follow user abbreviations.
```shell
% abbr --add gcm git checkout master
% abbr --add --session a apple
% abbr --show # or `abbr` with no arguments
% abbr --list-commands # or `abbr` with no arguments
abbr gcm="git checkout master"
abbr -S a="apple"
% source ~/.zshrc
% abbr --show
% abbr --list-commands
abbr gcm="git checkout master"
```
Expand Down
2 changes: 1 addition & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Key:
Look like zsh's `alias` not fish's `abbr`

- [ ] same flags as zsh's `alias`:
- [ ] `-L` list in the form of commands
- [x] `-L` list in the form of commands
- [ ] `-g` list/define global aliases
- [ ] support `-L -g` and maybe `-L -r`
- [ ] maybe? `-r` list/define regular aliases
Expand Down
55 changes: 29 additions & 26 deletions zsh-abbr.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ _zsh_abbr() {
local action_set number_opts opt opt_add opt_clear_session opt_dry_run \
opt_erase opt_expand opt_export_aliases opt_import_git_aliases \
opt_global opt_import_aliases opt_import_fish opt_session opt_list \
opt_rename opt_show opt_user opt_print_version release_date \
opt_rename opt_list_commands opt_user opt_print_version release_date \
scope_set should_exit text_bold text_reset util_usage version
action_set=false
number_opts=0
Expand All @@ -40,7 +40,7 @@ _zsh_abbr() {
opt_export_aliases=false
opt_import_aliases=false
opt_rename=false
opt_show=false
opt_list_commands=false
opt_user=false
opt_print_version=false
release_date="March 7 2020"
Expand All @@ -60,8 +60,8 @@ _zsh_abbr() {
${text_bold}abbr${text_reset} --import-git-aliases [SCOPE]
${text_bold}abbr${text_reset} --import-aliases [SCOPE]
${text_bold}abbr${text_reset} --list|-l
${text_bold}abbr${text_reset} --list-commands|-L|-s
${text_bold}abbr${text_reset} --rename|-r [SCOPE] OLD_ABBREVIATION NEW
${text_bold}abbr${text_reset} --show|-s
${text_bold}abbr${text_reset} --help|-h
${text_bold}abbr${text_reset} --version|-v
Expand Down Expand Up @@ -112,8 +112,8 @@ _zsh_abbr() {
or -r OLD_ABBREVIATION NEW_ABBREVIATION Renames an abbreviation,
from OLD_ABBREVIATION to NEW_ABBREVIATION.
o --show or -s Show all abbreviations in a manner suitable for export
and import.
o --list-commands or -L (or fishy -s) Show all abbreviations in a
manner suitable for export and import.
o --version or -v Show the current version.
Expand Down Expand Up @@ -205,8 +205,9 @@ _zsh_abbr() {
the scope. If you want it to be visible only to the current shell
use the -g flag.
The options add, export-aliases, erase, expand, import, list, rename,
and show are mutually exclusive, as are the session and user scopes.
The options add, export-aliases, erase, expand, import, list,
list-commands, and rename are mutually exclusive, as are the session
and user scopes.
$version $release_date"
version="zsh-abbr version 3.0.2"
Expand Down Expand Up @@ -460,9 +461,9 @@ _zsh_abbr() {
fi
}

function show() {
function list_commands() {
if [ $# -gt 0 ]; then
util_error " show: Unexpected argument"
util_error " list commands: Unexpected argument"
return
fi

Expand Down Expand Up @@ -682,13 +683,6 @@ _zsh_abbr() {
opt_import_git_aliases=true
((number_opts++))
;;
"--list"|\
"-l")
[ "$action_set" = true ] && util_bad_options
action_set=true
opt_list=true
((number_opts++))
;;
"--export-aliases")
[ "$action_set" = true ] && util_bad_options
action_set=true
Expand All @@ -701,6 +695,22 @@ _zsh_abbr() {
opt_import_aliases=true
((number_opts++))
;;
"--list-abbreviations"|\
"-l")
[ "$action_set" = true ] && util_bad_options
action_set=true
opt_list=true
((number_opts++))
;;
"--list-commands"|\
"-L"|\
"--show"|\
"-s") # "show" is for backwards compatability with v2
[ "$action_set" = true ] && util_bad_options
action_set=true
opt_list_commands=true
((number_opts++))
;;
"--rename"|\
"-r")
[ "$action_set" = true ] && util_bad_options
Expand All @@ -715,13 +725,6 @@ _zsh_abbr() {
opt_session=true
((number_opts++))
;;
"--show"|\
"-s")
[ "$action_set" = true ] && util_bad_options
action_set=true
opt_show=true
((number_opts++))
;;
"--user"|\
"-U")
[ "$scope_set" = true ] && util_bad_options
Expand Down Expand Up @@ -777,11 +780,11 @@ _zsh_abbr() {
rename "$@"

# default if arguments are provided
elif ! $opt_show && [ $# -gt 0 ]; then
elif ! $opt_list_commands && [ $# -gt 0 ]; then
add "$@"
# default if no argument is provided
else
show "$@"
list_commands "$@"
fi
} always {
unfunction -m "add"
Expand All @@ -794,9 +797,9 @@ _zsh_abbr() {
unfunction -m "import_fish"
unfunction -m "import_git_aliases"
unfunction -m "list"
unfunction -m "list_commands"
unfunction -m "print_version"
unfunction -m "rename"
unfunction -m "show"
unfunction -m "util_add"
unfunction -m "util_alias"
unfunction -m "util_error"
Expand Down

0 comments on commit 45b9a69

Please sign in to comment.