From 7418facc8353dabbbc3ad886f05b32ffcf499ace Mon Sep 17 00:00:00 2001 From: Henry Bley-Vroman Date: Sat, 7 Mar 2020 13:25:05 -0500 Subject: [PATCH] feat(list commands): support listing globals only --- README.md | 10 +++++++--- ROADMAP.md | 5 +++-- zsh-abbr.zsh | 20 ++++++++++++++++---- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 84ca9956..1e6a4377 100644 --- a/README.md +++ b/README.md @@ -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 ] ``` @@ -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 diff --git a/ROADMAP.md b/ROADMAP.md index 10a59b47..895ea885 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -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 diff --git a/zsh-abbr.zsh b/zsh-abbr.zsh index 099e272f..db4d1339 100755 --- a/zsh-abbr.zsh +++ b/zsh-abbr.zsh @@ -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() {