From 7d3857aacf6dcab081301f73777dd3488b4b272d Mon Sep 17 00:00:00 2001 From: Maximilian Friedersdorff Date: Mon, 14 Nov 2016 10:22:26 +0000 Subject: [PATCH] Pipe to less if output of la is larger than one screen --- bash/.bash_aliases | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bash/.bash_aliases b/bash/.bash_aliases index 879f20c..0bab62d 100644 --- a/bash/.bash_aliases +++ b/bash/.bash_aliases @@ -1,3 +1,5 @@ +#!/bin/bash + if [ -x /usr/bin/dircolors ]; then test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" alias ls='ls --color=auto' @@ -10,6 +12,12 @@ if [ -x /usr/bin/dircolors ]; then fi function la { - \ls -lah --color=always "$@" | less -r + ls_out=$(\ls -lah --color=always "$@") + let "allowed_lines = $(tput lines) - 3" + if [ $(echo "$ls_out" | wc -l) -le $allowed_lines ]; then + echo "$ls_out" + else + echo "$ls_out" | less -r + fi } alias tmux='TERM=xterm-256color tmux' -- 2.45.2