如何获取 zsh 内置命令的帮助消息?

如何获取 zsh 内置命令的帮助消息?

如果我想获得 bash 内置命令的简短使用消息,我可以help <builtin>在命令提示符下使用,例如

$ help export
export: export [-fn] [name[=value] ...] or export -p
    Set export attribute for shell variables.

    Marks each NAME for automatic export to the environment of subsequently
    executed commands.  If VALUE is supplied, assign VALUE before exporting.

    Options:
      -f        refer to shell functions
      -n        remove the export property from each NAME
      -p        display a list of all exported variables and functions

    An argument of `--' disables further option processing.

    Exit Status:
    Returns success unless an invalid option is given or NAME is invalid.

我怎样才能在 zsh 中做到这一点?我试过了

% export --help
zsh: bad option: -e

% help export
zsh: command not found: help

此外,“帮助”一词不在 中的任何地方man zshbuiltins

答案1

感谢@don_crissti 通过此链接Arch 维基文档
由于某种原因,Arch wiki 上的代码在调用时导致此错误

/home/velour/.zshrc:unalias:368:没有这样的哈希表元素:run-help

zsh --版本 => zsh 5.1.1 (x86_64-ubuntu-linux-gnu)

因此,为了使其正常工作,我将以下块添加到~/.zshrc,然后注释掉别名命令。

autoload -Uz run-help
autoload -Uz run-help-git
autoload -Uz run-help-svn
autoload -Uz run-help-svk
#unalias run-help
#alias help=run-help

并简单地调用

run-help <builtin>

所以现在我明白了

% run-help export

export [ name[=value] ... ]
       The specified names are marked for automatic export to the envi-
       ronment  of subsequently executed commands.  Equivalent to type-
       set -gx.  If a parameter specified does not already exist, it is
       created in the global scope.

答案2

上述函数的替代方法run-helpzman中提到的Reddit 评论。它是 Zinit 的一部分,但似乎独立工作。

答案3

添加以下内容.zshrc对我有用。
(基于 the_velour_fog 的答案)

unalias run-help
alias help=run-help
autoload -Uz run-help

之前run-help是 的别名man

$ zsh --version
zsh 5.9 (x86_64-apple-darwin18.7.0)
$ zsh
\$ type run-help
run-help is an alias for man
\$ unalias run-help
\$ type run-help
run-help not found
\$ autoload -Uz run-help
\$ type run-help
run-help is an autoload shell function
\$ alias help=run-help
\$ help export
export [ name[=value] ... ]
       The specified names are marked for automatic export to the envi-
       ronment  of subsequently executed commands.  Equivalent to type-
       set -gx.  If a parameter specified does not already exist, it is
       created in the global scope.

答案4

他们有自己的手册页:

man zshbuiltins

相关内容