Skip to content

Commit

Permalink
feat: refactor ls, list, and loaded commands
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
vladdoster committed Apr 10, 2023
1 parent 243f5bd commit a865907
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 44 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ Following commands are passed to `zinit ...` to obtain described effects.
### 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`. |
Expand All @@ -832,7 +832,7 @@ Following commands are passed to `zinit ...` to obtain described effects.
### 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. |
Expand All @@ -841,29 +841,29 @@ Following commands are passed to `zinit ...` to obtain described effects.

### 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. |

### 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. |
Expand Down
5 changes: 2 additions & 3 deletions _zinit
Original file line number Diff line number Diff line change
Expand Up @@ -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 '
Expand Down
6 changes: 3 additions & 3 deletions doc/zsdoc/zinit-autoload.zsh.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ ____
____

Has 107 line(s). Calls functions:
Has 111 line(s). Calls functions:

.zinit-delete
|-- .zinit-prompt
Expand Down Expand Up @@ -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_

Expand Down
1 change: 0 additions & 1 deletion doc/zsdoc/zinit-side.zsh.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions doc/zsdoc/zinit.zsh.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 21 additions & 19 deletions zinit-autoload.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'"
Expand Down
8 changes: 4 additions & 4 deletions zinit.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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|\
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 "$@"
;;
Expand Down

0 comments on commit a865907

Please sign in to comment.