From a86590762ac2bb5244db5d3cd7d99d32a9dc11fe Mon Sep 17 00:00:00 2001 From: Vladislav Doster Date: Sun, 9 Apr 2023 20:05:47 -0500 Subject: [PATCH] feat: refactor ls, list, and loaded commands Issues addressed: 1. Confusing and unintuitive command names Currently, two commands `loaded` and `list` will list installed plugins and a single command `ls` lists installed snippets. The namea don't make much sense or give context to their behavior, nor does having two commands with identical behavior. This PR removes the three commands in favor of two new commands `list-snippets` and `list-plugins`. The names align with the action they perform. 2. Uninformative output Current output is hard to grok. This PR cleans up the output format and uses color to help convey information. 3. Incorrect Output does not account for various situations with the only way to fix is to reload Zsh session which would not always fix it. See images below for the aforementioned situations. Signed-off-by: Vladislav Doster --- README.md | 28 +++++++++++----------- _zinit | 5 ++-- doc/zsdoc/zinit-autoload.zsh.adoc | 6 ++--- doc/zsdoc/zinit-side.zsh.adoc | 1 - doc/zsdoc/zinit.zsh.adoc | 1 + zinit-autoload.zsh | 40 ++++++++++++++++--------------- zinit.zsh | 8 +++---- 7 files changed, 45 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index b0438cd5..2ada429e 100644 --- a/README.md +++ b/README.md @@ -816,7 +816,7 @@ ### Loading and Unloading ### Completions | Command | Description | -| :------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | +| -------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | | `cclear` | Clear stray and improper completions. | | `cdclear [-q]` | Clear compdef replay list. `-q` – quiet. | | `cdisable {cname}` | Disable completion `cname`. | @@ -832,7 +832,7 @@ ### Completions ### Tracking of the Active Session | Command | Description | -| :--------------- | ------------------------------------------------- | +| ---------------- | ------------------------------------------------- | | `dclear` | Clear report of what was going on in session. | | `dstop` | Stop investigating what's going on in session. | | `dreport` | Report what was going on in session. | @@ -841,21 +841,21 @@ ### Tracking of the Active Session ### Reports and Statistics -| Command | Description | -| :--------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `ls` | List snippets in formatted and colorized manner. Requires `tree` program. | -| `bindkeys` | Lists bindkeys set up by each plugin. | -| `zstatus` | Overall Zinit status. | -| `report {plg-spec}` | Show plugin report. `--all` – do it for all plugins. | -| `status {plg-spec}` | Git status for plugin or svn status for snippet. `--all` – do it for all plugins and snippets. | -| `recently [time-spec]` | Show plugins that changed recently, argument is e.g. 1 month 2 days. | -| `times [-s] [-m] [-a]` | Statistics on plugin load times, sorted in order of loading. `-s` – use seconds instead of milliseconds. `-m` – show plugin loading moments. `-a` - show both plugin load times and loading moments | -| `loaded [keyword], list [keyword]` | Show what plugins are loaded (filter with 'keyword'). | +| Command | Description | +| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `bindkeys` | Lists bindkeys set up by each plugin. | +| `list-plugins [keyword]` | Show what plugins are loaded (filter with 'keyword'). | +| `list-snippets` | List snippets in formatted and colorized manner. Requires `tree` program. | +| `recently [time-spec]` | Show plugins that changed recently, argument is e.g. 1 month 2 days. | +| `report {plg-spec}` | Show plugin report. `--all` – do it for all plugins. | +| `status {plg-spec}` | Git status for plugin or svn status for snippet. `--all` – do it for all plugins and snippets. | +| `zstatus` | Display brief statistics for your Zinit installation. | +| `times [-a] [-m] [-s]` | Print load times for each plugin. `-s` – Times are printed in seconds. `-m` – Show plugin loading moments. `-a` - Times and loading moments are printed. | ### Compiling | Command | Description | -| :--------------------- | ------------------------------------------------------------------- | +| ---------------------- | ------------------------------------------------------------------- | | `compiled` | List plugins that are compiled. | | `compile {plg-spec}` | Compile plugin. `--all` – compile all plugins. | | `uncompile {plg-spec}` | Remove compiled version of plugin. `--all` – do it for all plugins. | @@ -863,7 +863,7 @@ ### Compiling ### Other | Command | Description | -| :--------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| ---------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `module` | Manage binary Zsh module shipped with Zinit, see `zinit module help`. | | `self-update` | Updates and compiles Zinit. | | `cd {plg-spec}` | Cd into plugin's directory. Also support snippets if fed with URL. | diff --git a/_zinit b/_zinit index 9dabf4d3..bfa3e27b 100644 --- a/_zinit +++ b/_zinit @@ -41,10 +41,9 @@ __zinit_commands(){ 'env-whitelist:Specify names (also patterns) of parameters to be left unchanged during an unload' 'glance:Look at plugins source' 'help:Usage information' - 'list:Show what plugins are loaded' + 'list-plugins:List status of all installed plugins' + 'list-snippets:List status of all installed snippets' 'load:Load plugin' - 'loaded:Show what plugins are loaded' - 'ls:List snippets in formatted and colorized manner' 'man:Display Zinit'\''s manpage' 'module:Manage binary Zsh module shipped with Zinit' 'recall:Fetch saved ice modifiers and construct ' diff --git a/doc/zsdoc/zinit-autoload.zsh.adoc b/doc/zsdoc/zinit-autoload.zsh.adoc index 0daa9950..431147fc 100644 --- a/doc/zsdoc/zinit-autoload.zsh.adoc +++ b/doc/zsdoc/zinit-autoload.zsh.adoc @@ -445,7 +445,7 @@ ____ ____ -Has 107 line(s). Calls functions: +Has 111 line(s). Calls functions: .zinit-delete |-- .zinit-prompt @@ -1161,10 +1161,10 @@ ____ ____ -Has 22 line(s). Calls functions: +Has 21 line(s). Calls functions: .zinit-show-registered-plugins - `-- zinit-side.zsh/.zinit-any-colorify-as-uspl2 + `-- zinit.zsh/+zinit-message Uses feature(s): _setopt_ diff --git a/doc/zsdoc/zinit-side.zsh.adoc b/doc/zsdoc/zinit-side.zsh.adoc index f87a81b8..a9b3378c 100644 --- a/doc/zsdoc/zinit-side.zsh.adoc +++ b/doc/zsdoc/zinit-side.zsh.adoc @@ -54,7 +54,6 @@ Called by: zinit-autoload.zsh/.zinit-recently zinit-autoload.zsh/.zinit-search-completions zinit-autoload.zsh/.zinit-show-completions - zinit-autoload.zsh/.zinit-show-registered-plugins zinit-autoload.zsh/.zinit-show-times zinit-autoload.zsh/.zinit-uncompile-plugin zinit-autoload.zsh/.zinit-unload diff --git a/doc/zsdoc/zinit.zsh.adoc b/doc/zsdoc/zinit.zsh.adoc index df8f16c8..3d662c6f 100644 --- a/doc/zsdoc/zinit.zsh.adoc +++ b/doc/zsdoc/zinit.zsh.adoc @@ -257,6 +257,7 @@ Called by: zinit-autoload.zsh/.zinit-delete zinit-autoload.zsh/.zinit-glance zinit-autoload.zsh/.zinit-self-update + zinit-autoload.zsh/.zinit-show-registered-plugins zinit-autoload.zsh/.zinit-show-zstatus zinit-autoload.zsh/.zinit-uninstall-completions zinit-autoload.zsh/.zinit-update-all-parallel diff --git a/zinit-autoload.zsh b/zinit-autoload.zsh index 75dd843d..bafe0650 100644 --- a/zinit-autoload.zsh +++ b/zinit-autoload.zsh @@ -770,27 +770,25 @@ ZINIT[EXTENDED_GLOB]="" .zinit-show-registered-plugins() { builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace} setopt extendedglob warncreateglobal typesetsilent noshortloops - typeset -a filtered local keyword="$1" - - keyword="${keyword## ##}" - keyword="${keyword%% ##}" - if [[ -n "$keyword" ]]; then - builtin print "Installed plugins matching ${ZINIT[col-info]}$keyword${ZINIT[col-rst]}:" - filtered=( "${(M)ZINIT_REGISTERED_PLUGINS[@]:#*$keyword*}" ) - else - filtered=( "${ZINIT_REGISTERED_PLUGINS[@]}" ) - fi - - local i - for i in "${filtered[@]}"; do - [[ "$i" = "_local/zinit" ]] && continue - .zinit-any-colorify-as-uspl2 "$i" - # Mark light loads - [[ "${ZINIT[STATES__$i]}" = "1" ]] && REPLY="$REPLY ${ZINIT[col-info]}*${ZINIT[col-rst]}" - builtin print -r -- "$REPLY" - done + keyword="${keyword## ##}" + keyword="${keyword%% ##}" + if [[ -n "$keyword" ]]; then + +zinit-message "{i} Installed plugins matching {info}$keyword{rst}:" + filtered=( "${(M)ZINIT[@]:#STATES__*$keyword*}" ) + else + filtered=(${${(M)${(k)ZINIT[@]}:##STATES__*}//[A-Z]*__/}) + fi + local i + +zinit-message '{u}{info}Registered plugins{rst}' + for i in "${(o)filtered[@]}"; do + [[ "$i" = "local/zinit" ]] && continue + local is_loaded='{error}U' + (( "ZINIT[STATES__$i]" )) && is_loaded="{happy}L" + +zinit-message -C2 -- $is_loaded{rst} $i + done + +zinit-message -- '{nl}{note}Note:{rst} Loaded plugins are denoted by a {num}*' } # ]]] # FUNCTION: .zinit-unload [[[ # 1. call the zsh plugin's standard *_plugin_unload function @@ -2766,6 +2764,9 @@ ZINIT[EXTENDED_GLOB]="" if (( $#o_yes )) || ( .zinit-prompt "Delete all plugins and snippets (${#all_installed} total)"); then command rm -rf -- ${(@)all_installed} command rm -f -- $ZINIT[HOME_DIR]/**/*(-@N) + for f in ${(M)${(k)ZINIT[@]}:##STATES__*~*local/zinit*}; do + builtin unset "ZINIT[$f]" + done local rc=$? +zinit-message "{m} Deleted all completed with return code {num}${rc}{rst}" return $rc @@ -2801,6 +2802,7 @@ ZINIT[EXTENDED_GLOB]="" } command rm -rf -- ${(q)${${local_dir:#[/[:space:]]##}:-${TMPDIR:-${TMPDIR:-/tmp}}/abcYZX321}}(N) # delete files command rm -f -- $ZINIT[HOME_DIR]/**/*(-@N) # delete broken symlins + builtin unset "ZINIT[STATES__${ICE2[id-as]}]" || builtin unset "ZINIT[STATES__${ICE2[teleid]}]" +zinit-message "{m} Uninstalled $i" else +zinit-message "{w} No available plugin or snippet with the name '$i'" diff --git a/zinit.zsh b/zinit.zsh index 5d2125a1..003de923 100644 --- a/zinit.zsh +++ b/zinit.zsh @@ -121,7 +121,7 @@ fpath|\ glance|\ help|\ ice|\ -light|list|load|loaded|ls|\ +light|list-plugins|list-snippets|load|\ man|module|\ recall|recently|report|run|\ self-update|snippet|srv|status|stress|\ @@ -2981,10 +2981,10 @@ You can try to prepend {apo}${___q}{lhi}@{apo}'{error} to the ID if the last ice .zinit-show-report "${2%%(///|//|/)}" "${3%%(///|//|/)}"; ___retval=$? fi ;; - (loaded|list) + (list-plugins) # Show list of loaded plugins. .zinit-show-registered-plugins "$2" - ;; + ;; (clist|completions) # Show installed, enabled or disabled, completions. # Detect stray and improper ones. @@ -3106,7 +3106,7 @@ You can try to prepend {apo}${___q}{lhi}@{apo}'{error} to the ID if the last ice (version) zi::version ;; - (ls) + (list-snippets) shift .zinit-ls "$@" ;;