aboutsummaryrefslogtreecommitdiff
path: root/sh/shrc.d/ls.sh
diff options
context:
space:
mode:
Diffstat (limited to 'sh/shrc.d/ls.sh')
-rw-r--r--sh/shrc.d/ls.sh15
1 files changed, 15 insertions, 0 deletions
diff --git a/sh/shrc.d/ls.sh b/sh/shrc.d/ls.sh
new file mode 100644
index 00000000..eec25eb7
--- /dev/null
+++ b/sh/shrc.d/ls.sh
@@ -0,0 +1,15 @@
+# Our ~/.profile should already have made a directory with the supported
+# options for us; if not, we won't be wrapping ls(1) with a function at all
+[ -d "$HOME"/.cache/ls ] || return
+
+# Define function proper
+ls() {
+
+ # Add --color if the terminal has at least 8 colors
+ [ -e "$HOME"/.cache/ls/color ] &&
+ [ "$({ tput colors || tput Co ; } 2>/dev/null)" -ge 8 ] &&
+ set -- --color=auto "$@"
+
+ # Run ls(1) with the concluded arguments
+ command ls "$@"
+}