From 1ddfd22747b7ea304d7e58877b484ff49485f2f8 Mon Sep 17 00:00:00 2001 From: Thomas Ulmer Date: Mon, 29 Dec 2025 15:02:35 -0800 Subject: util: small ls+pager util --- lk.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 lk.sh (limited to 'lk.sh') diff --git a/lk.sh b/lk.sh new file mode 100755 index 0000000..967332a --- /dev/null +++ b/lk.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# This is helper that should replace a number of common commands +# +# It is intended to be named `lk`, short for "look" + +longView=${PAGER:-$(which less || which more || echo "cat")} +dirView="ls --color=auto -Alh" + +if [ $# -lt 1 ]; then + # take stdin instead + $dirView $(pwd) +fi + +for a in $@; do + if [ $a == "" ]; then + echo "Empty argument skipped" + elif [ ! -e $a ]; then + echo "$a does not exist" 1>&2 + exit -1 + elif [ -d $a ]; then + $dirView $a + elif [ $(tput lines) -ge $(($(wc -l < $a) - 2)) ]; then + cat $a + else + ${longView} $a + fi +done -- cgit v1.2.3