Skip to content

Commit

Permalink
feat(list commands): support listing globals only
Browse files Browse the repository at this point in the history
  • Loading branch information
olets committed Mar 7, 2020
1 parent 45b9a69 commit 7418fac
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Default is user.
| --import-fish [(--global | -g)] [--dry-run] arg
| --import-git-aliases [--dry-run]
| (--list | -l)
| (--list-commands | -L | -s) [(--global | -g)]
| (--list-commands | -L | -s) [(--session | -S) | (--user | -U)] [(--global | -g)]
| (--rename | -r ) [(--global | -g)] [--dry-run] args
]
```
Expand Down Expand Up @@ -434,10 +434,14 @@ Abbreviations can also be manually renamed in the `ZSH_USER_ABBREVIATIONS_PATH`.
#### List Commands
```shell
abbr [(--list-commands | -L | -s)] [(--global | -g)]
abbr [(--list-commands | -L | -s)] [(--session | -S) | (--user | -U)] [(--global | -g)]
```
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.
List all the abbreviations available in the current session as commands. Session abbreviations are marked `-S` and follow user abbreviations.
Use the **--session** or **-S** flag to list only a session abbreviations.
Use the **--global** flag to list only global abbreviations.
```shell
% abbr --add gcm git checkout master
Expand Down
5 changes: 3 additions & 2 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ Look like zsh's `alias` not fish's `abbr`

- [ ] same flags as zsh's `alias`:
- [x] `-L` list in the form of commands
- [ ] `-g` list/define global aliases
- [ ] support `-L -g` and maybe `-L -r`
- [x] `-g` list/define global aliases
- [x] support `-L -g`
- [ ] maybe? `-r` list/define regular aliases
- [ ] abbr on its own (or with -g or -r) lists like alias [-g|-r]
- [ ] don't do this one: `-m` list aliases that match a pattern
- [ ] don't do this one: `-s` list/define suffix aliases

Expand Down
20 changes: 16 additions & 4 deletions zsh-abbr.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,27 @@ _zsh_abbr() {
return
fi

cat $ZSH_ABBR_USER_PATH
if ! $opt_session; then
for abbreviation expansion in ${(kv)ZSH_ABBR_USER_GLOBALS}; do
printf "abbr -g %s=\"%s\"\\n" "$abbreviation" "$expansion"
done

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

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

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

function util_add() {
Expand Down

0 comments on commit 7418fac

Please sign in to comment.