Skip to content

Commit 44f782c

Browse files
committed
_cargo: Explain how _cargo_cmds works
1 parent 29e6278 commit 44f782c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/etc/_cargo

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,18 @@ _cargo() {
422422

423423
_cargo_cmds() {
424424
local -a commands
425-
commands=( ${${${(M)"${(f)$(cargo --list)}":# *}/ ##/}/ ##/:} )
425+
# This uses Parameter Expansion Flags, which is an Zsh built-in features.
426+
# See more: http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags
427+
# and http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion
428+
#
429+
# # How this work?
430+
#
431+
# First it splits the result of `cargo --list` at newline, then it removes the first line.
432+
# Then it removes indentation (4 whitespaces) before each items. (Note the x## pattern [1]).
433+
# Then it replaces those spaces between item and description with a `:`
434+
#
435+
# [1]: https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org#patterns
436+
commands=( ${${${(M)"${(f)$(cargo --list)}":# *}/ ##/}/ ##/:} )
426437
_describe 'command' commands
427438
}
428439

0 commit comments

Comments
 (0)