Sadly, there's no convenient way to install the man
utility on Windows, and even if there was, it wouldn't help you because the *.1
manual files aren't packaged for Windows. (It's the classic chicken-and-egg problem.)
However, if you're using Git BASH from Git for Windows, you can simply add this line to your ~/.bashrc
file:
man() { "$1" --help 2>&1 | less; }
Now when you type man [command]
at the Bash prompt, you'll see the command's --help
text. It's not quite as good as a manual page, but it tends to have the most important information.
Piping it to less
gives you the familiar man
interface:
- Scroll up and down with the arrow keys.
- Press the letter keys U or D to scroll faster.
- Press / to initiate a text search.
- Press Q to quit the help screen and return to the shell prompt.
The 2>&1
redirect ensures you'll see a message if the command isn't found, otherwise less
would just give you an empty screen.
If you also want to see help text for shell-builtins and other goodies, add this to ~/.bashrc
instead:
function man()
{
(
exec 2>&1
type "$1" 2>/dev/null # Print command type.
case "$(type -t "$1")" in
alias|function)
: # Do nothing. (Safest option. See below for possible alternatives.)
;;
builtin|keyword)
help -m "$1" # Show Bash help.
;;
file|*)
"$1" --help # Show command's help.
;;
esac
) | less
}
Alternative code for the alias
and function
cases:
alias)
eval "$1" --help # Resolve the alias. Potentially unsafe!
;;
function)
"$1" --help # Execute the function. Potential for unintended consequences!
;;
This alternative code would hopefully show --help
text for whatever command the alias/function points to. However, it makes assumptions about how the alias/function is constructed, so it's not guaranteed to work for all functions/aliases. Also, use of eval
is generally discouraged (although here we do at least know that we're evaluating an alias name, which can only contain a restricted set of characters). Anyway, this code can have unintended consequences, hence I decided to leave it out of the main example.