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 <mvdoster@gmail.com>
This commit is contained in:
Vladislav Doster 2023-04-09 20:05:47 -05:00
parent 243f5bd6d2
commit a86590762a
No known key found for this signature in database
7 changed files with 45 additions and 44 deletions

View file

@ -816,7 +816,7 @@ ### Loading and Unloading<a name="loading-and-unloading"></a>
### Completions<a name="completions-1"></a>
| 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<a name="completions-1"></a>
### Tracking of the Active Session<a name="tracking-of-the-active-session"></a>
| 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<a name="tracking-of-the-active-session"></a>
### Reports and Statistics<a name="reports-and-statistics"></a>
| 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<a name="compiling"></a>
| 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<a name="compiling"></a>
### Other<a name="other"></a>
| 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. |

5
_zinit
View file

@ -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 '

View file

@ -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_

View file

@ -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

View file

@ -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

View file

@ -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'"

View file

@ -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 "$@"
;;