Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I read documentation about built in zsh commands?

It's frustrating when I do something like man bindkey and i get:

 BUILTIN(1)                BSD General Commands Manual               BUILTIN(1)  NAME      builtin, !, %, ., :, @, {, }, alias, alloc, bg, bind, bindkey, break, breaksw, builtins, case, cd, chdir, command,      complete, continue, default, dirs, do, done, echo, echotc, elif, else, end, endif, endsw, esac, eval, exec, exit,      export, false, fc, fg, filetest, fi, for, foreach, getopts, glob, goto, hash, hashstat, history, hup, if, jobid,      jobs, kill, limit, local, log, login, logout, ls-F, nice, nohup, notify, onintr, popd, printenv, pushd, pwd, read,      readonly, rehash, repeat, return, sched, set, setenv, settc, setty, setvar, shift, source, stop, suspend, switch,      telltc, test, then, time, times, trap, true, type, ulimit, umask, unalias, uncomplete, unhash, unlimit, unset,      unsetenv, until, wait, where, which, while -- shell built-in commands  SYNOPSIS      builtin [-options] [args ...]  DESCRIPTION      Shell builtin commands are commands that can be executed within the running shell's process.  Note that, in the 

Is there an easy way to access the documentation for such commands?

like image 889
John Bachir Avatar asked Dec 10 '10 03:12

John Bachir


People also ask

Where are zsh commands stored?

ZSH is a popular shell built on top of bash. It stores your command history in the . zsh_history file in your home directory.

Are zsh commands the same as bash?

Zsh has floating-point support that Bash does not possess. Hash data structures are supported in Zsh that are not present in Bash. The invocation features in Bash is better when comparing with Zsh. The prompt look can be controlled in Bash, whereas Zsh is customizable.

Is zsh shell script?

A ZSH shell script is a text file that contains instructions or commands to be executed by the ZSH shell. The ZSH shell is an extended version of the Bourne Again Shell; thus, most commands and scripts written for bash will work on ZSH.

What is the Help command in zsh?

zsh helpfully comes installed with help files for all the builtins and a run-help command to help you access those help files.


2 Answers

The key information for getting a more useful help utility is actually included with Zsh, it's just a matter of finding the critical—and poorly discoverable—man page: man zshcontrib (here on the web), which describes the run-help widget:

By default, run-help is an alias for the man command, so this often fails when the command word is a shell builtin or a user-defined function. By redefining the run-help alias, one can improve the on-line help provided by the shell.

It further explains how to replace it with a built-in improvement.

After setting this up, calling run-help for names of builtins, completion functions and so forth will now try to show you extracted documentation, or show you the right containing man page, etc. For example run-help bindkey outputs:

bindkey    See the section `Zle Builtins' in zshzle(1). 

which could be better. For a better example, run-help history shows the Zsh man page section for fc, which is the command that underlies history.

Also handy to note: ESC-h will call run-help for the command on the current input line.

I presume this setup isn't the default because extracting the granular help data and setting HELPDIR to point to it might be a packaging decision left to OS distributions. There's also a user choice: the autoload run-help util is useful without setting HELPDIR at all. It seems to be good at taking you to the right man page even if it can't jump to the exact section for one item. Some may prefer this to running into cases like the bindkey example above which just wastes time. (Why they default to alias run-help=man then, I cannot fathom).

For Zsh version 5.0.3 or newer

The helpfiles extractions are likely included with the Zsh distribution. It's just a matter of finding them on your system to set HELPDIR if you wish—likely candidates are in /usr/share/zsh or /usr/local/share/zsh, look for a help subdirectory.

For versions of Zsh before 5.0.3

You will likely need to follow the procedure detailed in man zshcontrib yourself to generate the help files. It's a little annoying to need to do this, but otherwise quick and painless.

Find your installed version with zsh --version and obtain the corresponding source tarball from the sourceforge archive. Then run the helpfiles script as shown in the man page and set the target as HELPDIR in your ~/.zshrc.

like image 75
ches Avatar answered Oct 06 '22 13:10

ches


Try either of these:

man zshbuiltins 

or

man zshall 

The man pages for zsh are divided up by topic, man zsh is mostly a table of contents and introduction while man zshall is everything (24628 lines on my system compared to 5242 for man bash).

As for bindkey, man zshbuiltins will refer you to man zshzle.

like image 34
Dennis Williamson Avatar answered Oct 06 '22 12:10

Dennis Williamson