Just now, dpkg --help
spit out three pages of output in my face. I was maybe interested in the first ten lines, which show the general usage and most common arguments.
I'd like that, whenever I run a program (any program) with --help
as the only argument, if the output is longer than $(tput lines)
, it would automatically get piped through less
. Is it easily doable in bash?
Edit: In the end, the best solution for me was to switch to zsh. Either one of the following snippets in your ~/.zshrc
will do the job; each one has its own tradeoffs:
# Modify the input line before it runs
function lessify() {
if [[ "$BUFFER" =~ " --help$" ]] ; then
BUFFER="$BUFFER | less -FX"
fi
zle accept-line
}
zle -N lessify_widget lessify
# Bind to the Enter key
bindkey '^M' lessify_widget
or
# Alias --help ; ignore rest of the line
alias -g -- --help="--help | less -FX ; true "
Also, in researching this question, I've probably wasted more time than this will ever save me. Don't regret it one bit.
zsh
byalias -g
and not too easy inbash
. May be you'd satisfy withman dpkg
? – Costas Feb 12 '15 at 12:37man
always usesless
, which you'll have to exit - that's one keypress I'd like to avoid; and c) sometime I automatically type<some_program> --help
just out of habit. – Mihai Feb 12 '15 at 12:42alias --help='--help | less -F'
might just possibly work. I'll check it and update this comment, and then you could post this as an answer. ... Edit: No luck. An alias must be the first word of a command. – Mihai Feb 12 '15 at 13:19#!/bin/bash <newline> $1 --help | less -F
which you can call asHelp <program>
. Do not know if this works, just a quick idea. – Simon Klaver Feb 12 '15 at 13:26expect
, but seriously, you should not do this:expect -c 'spawn bash; interact -- "--help\r" {send -- "--help | less\r"}
– glenn jackman Feb 12 '15 at 14:52m
set as an alias toless
(I used to usemore
, hence them
) and all I need to do is typecommand --help | m
to get what you're after. Is it really worth writing a function for this? – terdon Feb 12 '15 at 16:24