0

I use "--help" or "-h" a lot. By default it uses cat to open help file. How can i set it to use less by default. I want the result of "command --help |less" to be the same as "command --help"

seven-phases-max
  • 11,765
  • 1
  • 45
  • 57

2 Answers2

3

An alias for --help wouldn't work. Aliases only apply to command names, not to their arguments. I wouldn't recommend a completely invisible solution, anyways. Too much command-line magic can create bad habits.

You could create a help command instead.

h() { "$@" --help | less; }
$ h cat
Usage: cat [OPTION]... [FILE]...
<snip>
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
2

Commands to not default to cat they just write to standard output.

Some comments (e.g., man) send the output to the application specified by the PAGER variable. You can set it to your favourite pager

export PAGER=less

But this will only work for applications that actually support it.

Otherwise you will have to pipe your commands as in your question.

Matteo
  • 14,696
  • 9
  • 68
  • 106