I'd like to configure bash to page the output of all commands. Essentially, I want bash to behave as if every command I enter ended with '| less'. Is this possible?
2 Answers
You could do this:
$ bind '"\C-j": "|less\C-m"'
Or put this in your ~/.inputrc
:
"\C-j": "|less\C-m"
Then when you want to do ls -l|less
you'd type ls -l
and press control-J
instead of <enter>
.
I would not recommend swapping the j and m in the bind command (or in the .inputrc file). Every time you'd press <enter>
you'd get |less
added which could be pretty annoying.
-
1
-
Dennis, That rocks! ZSH equivalent is: bindkey -s "\C-j" "|less\C-m" Jun 26, 2009 at 11:41
-
@dennis-williamson, did you know how can I fix this binding, for queued commands? For example enter in bash "sleep 10", and don't wait when "sleep 10" finished, "ls" + enter, and for "ls" command "|less" will be added.– azatApr 25, 2013 at 20:36
-
@azat: It works for me. I tried by using the
bind
command shown above (or the.inputrc
binding), typingsleep 10
and immediately typingls -l
(don't press enter) and then press Control-J (the enter is built in to the binding as\C-m
). Apr 26, 2013 at 14:02 -
1@azat: Oh! To fix that bind the sequence to something other than Control-J and use that keystroke to add the
less
and carriage return to commands that you want. The reason for this problem is that Control-J is normally bound toaccept-line
as is Control-M (enter). Apr 26, 2013 at 15:40
I'm not sure if this is possible, but you can definitely make it easier on yourself by doing something like this in your .bashrc:
alias p='less'
ll |p
then becomes a paged listing.
EDIT: As a note though this still wont work for something that is going to STDERR. You would need to something like: errorcommand 2>&1 |p