Re: [dev] [ubase] pager

From: hiro <23hiro_AT_gmail.com>
Date: Fri, 10 Feb 2017 10:53:21 +0100

the problem is when i *know* stuff fill be very long, but I still want
to start reading from the beginning. in tmux i don't know how to start
scrolling from top of my last command. I don't want to scroll there
manually. also in page i can use pgup/down in tmux i have to do crazy
emacs-combinations first.

On 2/10/17, Eric Pruitt <eric.pruitt_AT_gmail.com> wrote:
> On Fri, Feb 10, 2017 at 08:26:11AM +0100, robin wrote:
>> I usually pipe into less whenever something overflows the terminal
>> height, but having to type 2>&1 to see stderr is a bit cumbersome. In
>> dvtm Shift-PageUp is much easier.
>
> I use a generic wrapper function in Bash:
>
> # $1 Name or path of the command to execute.
> # $2 White-space separated list of options to pass to the command
> # when stdout is a TTY. If there are no TTY-dependent options
> # this should be "--".
> # $_AT_ Arguments to pass to command.
> #
> function -paginate()
> {
> local errfd=1
>
> local command="$1"
> local tty_specific_args="$2"
> shift 2
>
> if [[ -t 1 ]]; then
> test "$tty_specific_args" != "--" || tty_specific_args=""
> test -t 2 || errfd=2
> "$command" $tty_specific_args "$_AT_" 2>&"$errfd" | less -X -F -R
> return "${PIPESTATUS[0]/141/0}" # Ignore SIGPIPE failures.
> fi
>
> "$command" "$_AT_"
> }
>
> Then I have around 30 aliases for various commands I use like this:
>
> alias cat='-paginate cat --'
> alias grep='-paginate grep --color=always'
> alias ps='-paginate ps --cols=$COLUMNS --sort=uid,pid -N --ppid 2 -p 2'
>
> Output is only paginated when stdout is a TTY so I can still use pipes,
> and the less flags ensure that less will exit if the output fits on one
> screen. I also use tmux, but I find less to be less painful to use than
> copy mode in tmux when I don't need to actually copy text.
>
> Eric
>
>
Received on Fri Feb 10 2017 - 10:53:21 CET

This archive was generated by hypermail 2.3.0 : Fri Feb 10 2017 - 11:00:17 CET