Skip to content

Commit

Permalink
feat(list commands): support listing users only
Browse files Browse the repository at this point in the history
  • Loading branch information
olets committed Mar 7, 2020
1 parent a5cab16 commit 9544e98
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,11 @@ abbr [(--list-commands | -L | -s)] [(--session | -S) | (--user | -U)] [(--global
List all the abbreviations available in the current session as commands. Regular abbreviations follow global abbreviations. Session abbreviations follow user abbreviations.
Use the **--session** or **-S** flag to list only a session abbreviations.
Use the **--session** or **-S** scope flag to list only a session abbreviations. Use the **--user** or **-U** scope flag to list only a session abbreviations.
Use the **--global** or **-g** flag to list only global abbreviations.
Use the **--global** or **-g** type flag to list only global abbreviations. Use the **--regular** or **-r** type flag to list only global abbreviations.
Use the **--regular** or **-r** flag to list only global abbreviations.
Combine a scope flag and a type flag to further limit the output.
```shell
% abbr --add gcm="git checkout master"
Expand Down
51 changes: 25 additions & 26 deletions zsh-abbr.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ _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_type_global opt_import_aliases opt_import_fish opt_session opt_list \
opt_type_regular opt_rename opt_list_commands opt_user \
opt_print_version type_set release_date scope_set should_exit \
text_bold text_reset util_usage version
opt_import_aliases opt_import_fish opt_list opt_list_commands \
opt_print_version opt_rename opt_scope_session opt_scope_user \
opt_type_global opt_type_regular type_set release_date scope_set \
should_exit text_bold text_reset util_usage version
action_set=false
number_opts=0
opt_add=false
Expand All @@ -42,8 +42,8 @@ _zsh_abbr() {
opt_list_commands=false
opt_type_regular=false
opt_rename=false
opt_session=false
opt_user=false
opt_scope_session=false
opt_scope_user=false
opt_print_version=false
type_set=false
release_date="March 7 2020"
Expand Down Expand Up @@ -256,7 +256,7 @@ _zsh_abbr() {
return
fi

if $opt_session; then
if $opt_scope_session; then
if $opt_type_global; then
if (( ${+ZSH_ABBR_SESSION_GLOBALS[$1]} )); then
unset "ZSH_ABBR_SESSION_GLOBALS[${(b)1}]"
Expand Down Expand Up @@ -317,7 +317,7 @@ _zsh_abbr() {
return
fi

if $opt_session; then
if $opt_scope_session; then
util_alias ZSH_ABBR_SESSION_GLOBALS $1
util_alias ZSH_ABBR_SESSION_COMMANDS $1
else
Expand Down Expand Up @@ -425,7 +425,7 @@ _zsh_abbr() {
return
fi

if ! $opt_session; then
if ! $opt_scope_session; then
if ! $opt_type_regular; then
for abbreviation expansion in ${(kv)ZSH_ABBR_USER_GLOBALS}; do
printf "abbr -g %s=\"%s\"\\n" "$abbreviation" "$expansion"
Expand All @@ -439,16 +439,18 @@ _zsh_abbr() {
fi
fi

if ! $opt_type_regular; then
for abbreviation expansion in ${(kv)ZSH_ABBR_SESSION_GLOBALS}; do
printf "abbr -S -g %s=\"%s\"\\n" "$abbreviation" "$expansion"
done
fi
if ! $opt_scope_user; then
if ! $opt_type_regular; then
for abbreviation expansion in ${(kv)ZSH_ABBR_SESSION_GLOBALS}; do
printf "abbr -S -g %s=\"%s\"\\n" "$abbreviation" "$expansion"
done
fi

if ! $opt_type_global; then
for abbreviation expansion in ${(kv)ZSH_ABBR_SESSION_COMMANDS}; do
printf "abbr -S %s=\"%s\"\\n" "$abbreviation" "$expansion"
done
if ! $opt_type_global; then
for abbreviation expansion in ${(kv)ZSH_ABBR_SESSION_COMMANDS}; do
printf "abbr -S %s=\"%s\"\\n" "$abbreviation" "$expansion"
done
fi
fi
}

Expand All @@ -470,7 +472,7 @@ _zsh_abbr() {
return
fi

if $opt_session; then
if $opt_scope_session; then
if $opt_type_global; then
expansion=${ZSH_ABBR_SESSION_GLOBALS[$1]}
else
Expand Down Expand Up @@ -522,7 +524,7 @@ _zsh_abbr() {
util_error " add: ABBREVIATION ('$abbreviation') may not contain an equals sign"
fi

if $opt_session; then
if $opt_scope_session; then
if $opt_type_global; then
if ! (( ${+ZSH_ABBR_SESSION_GLOBALS[$1]} )); then
if $opt_dry_run; then
Expand Down Expand Up @@ -630,7 +632,7 @@ _zsh_abbr() {
local type
type="user"

if $opt_session; then
if $opt_scope_session; then
type="session"
fi

Expand Down Expand Up @@ -750,13 +752,14 @@ _zsh_abbr() {
"-S")
[ "$scope_set" = true ] && util_bad_options
scope_set=true
opt_session=true
opt_scope_session=true
((number_opts++))
;;
"--user"|\
"-U")
[ "$scope_set" = true ] && util_bad_options
scope_set=true
opt_scope_user=true
((number_opts++))
;;
"--version"|\
Expand All @@ -780,10 +783,6 @@ _zsh_abbr() {

shift $number_opts

if ! $opt_session; then
opt_user=true
fi

if $opt_add; then
add "$@"
elif $opt_clear_session; then
Expand Down

0 comments on commit 9544e98

Please sign in to comment.