aboutsummaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-24 11:52:27 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-24 11:52:27 +1200
commit565c808c0b732cca4579f7e8883e7aaac3c3aa62 (patch)
tree644e04b7e4fbbe7c997d6fb3df2ddd882d2189a3 /sh
parentForce --hide-control-chars on ls(1) if available (diff)
downloaddotfiles-565c808c0b732cca4579f7e8883e7aaac3c3aa62.tar.gz
dotfiles-565c808c0b732cca4579f7e8883e7aaac3c3aa62.zip
Add lore()
Diffstat (limited to 'sh')
-rw-r--r--sh/shrc.d/lore.sh28
1 files changed, 28 insertions, 0 deletions
diff --git a/sh/shrc.d/lore.sh b/sh/shrc.d/lore.sh
new file mode 100644
index 00000000..2d7c0bec
--- /dev/null
+++ b/sh/shrc.d/lore.sh
@@ -0,0 +1,28 @@
+# Pipe ls(1) output through PAGER; mostly to preserve coloring interactively
+# through less(1), but it'll work fine with plain ls(1) and more(1)
+lore() {
+
+ # Add --color=always if the terminal has at least 8 colors; we have to add
+ # "always" to coax ls(1) into emitting colors even though it can tell its
+ # stdout isn't a terminal but a pager
+ [ -e "$HOME"/.cache/ls/color ] &&
+ [ "$({ tput colors || tput Co ; } 2>/dev/null)" -ge 8 ] &&
+ set -- --color=always "$@"
+
+ # Prefer -A/--almost-all (exclude "." and "..") if available
+ if [ -e "$HOME"/.cache/ls/almost-all ] ; then
+ set -- -Al "$@"
+ else
+ set -- -al "$@"
+ fi
+
+ # Run whatever `ls` gives us; it might be our function wrapper; that's OK
+ ls "$@" |
+
+ # Run the appropriate pager; if it's less(1), we can tack on -R (though my
+ # ~/.lesskey does this anyway)
+ case $PAGER in
+ less) "$PAGER" -R ;;
+ *) "$PAGER" ;;
+ esac
+}