Can't write function to replicate the functionality of Bash's 'help' command

87 views Asked by At

I'm trying to replicate Bash's help command in my .zshrc. I thought this would work:

function help {
  bash -c "help $@"
}

but this only works when I only pass a single argument -- for instance, help exit. It does not work when I pass options to help, such as help -m exit (which works in Bash). However, literally typing bash -c "help -m exit" works as expected. I imagine this has something to do with how quoting works in the shell, but I can't figure this out.

2

There are 2 answers

3
ehwas On BEST ANSWER

You can use

function help {
  bash -c "help $*"
}
0
Marco Mariani On

I suppose you need help for using zsh, not for bash. Bash doesn't know anything about zsh builtins and features, and the common builtins are different enough to warrant separate documentation pages.

The equivalent of bash's help builtin is run-help, but it is not active by default. It will also call man for you and comes with a few useful wrappers.

TLDR; put this in .zshrc

autoload -Uz run-help autoload -Uz run-help-git autoload -Uz run-help-ip autoload -Uz run-help-openssl autoload -Uz run-help-p4 autoload -Uz run-help-sudo autoload -Uz run-help-svk autoload -Uz run-help-svn alias help=run-help

https://wiki.archlinux.org/index.php/zsh#Help_command