aboutsummaryrefslogtreecommitdiff
path: root/sh/profile.d
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-15 21:47:45 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-15 21:47:45 +1200
commit9d77b8a29e82e00035e2a8aadbf228d4c875fefe (patch)
tree0ae2fed6618acaa050f369af6057c9baff015266 /sh/profile.d
parentKeep grep(1) option metadata in cache (diff)
downloaddotfiles-9d77b8a29e82e00035e2a8aadbf228d4c875fefe.tar.gz
dotfiles-9d77b8a29e82e00035e2a8aadbf228d4c875fefe.zip
Keep ls(1) option metadata in cache
Diffstat (limited to 'sh/profile.d')
-rw-r--r--sh/profile.d/ls.sh43
1 files changed, 28 insertions, 15 deletions
diff --git a/sh/profile.d/ls.sh b/sh/profile.d/ls.sh
index a3cc84b7..7eb61fde 100644
--- a/sh/profile.d/ls.sh
+++ b/sh/profile.d/ls.sh
@@ -1,18 +1,31 @@
-# Store ls(1)'s --help output in a variable
-ls_help=$(ls --help 2>/dev/null)
+# Test that we have metadata about what options this system's ls(1) supports,
+# and try to create it if not
+(
+ # Create a directory to hold metadata about ls(1)
+ lcd=$HOME/.cache/ls
+ if ! [ -d "$lcd" ] ; then
+ mkdir -p -- "$lcd" || exit
+ fi
-# Run dircolors(1) to export LS_COLORS if available and appropriate
-case $ls_help in
- *--color*)
- if command -v dircolors >/dev/null 2>&1 ; then
- if [ -r "$HOME"/.dircolors ] ; then
- eval "$(dircolors --sh -- "$HOME"/.dircolors)"
- else
- eval "$(dircolors --sh)"
- fi
+ # Write ls(1)'s --help output to a file, even if it's empty
+ if ! [ -f "$lcd"/help ] ; then
+ ls --help >"$lcd"/help 2>/dev/null || exit
+
+ # Iterate through some useful options and create files to show they're
+ # available
+ if grep -q -- --color "$lcd"/help ; then
+ touch -- "$lcd"/color || exit
fi
- ;;
-esac
+ fi
+) || return
-# We're done parsing ls(1)'s --help output now
-unset -v ls_help
+# Run dircolors(1) to export LS_COLORS if available and appropriate
+if [ -e "$HOME"/.cache/ls/color ] ; then
+ if command -v dircolors >/dev/null ; then
+ if [ -r "$HOME"/.dircolors ] ; then
+ eval "$(dircolors --sh -- "$HOME"/.dircolors)"
+ else
+ eval "$(dircolors --sh)"
+ fi
+ fi
+fi