aboutsummaryrefslogtreecommitdiff
path: root/sh/profile.d/ls.sh
diff options
context:
space:
mode:
Diffstat (limited to 'sh/profile.d/ls.sh')
-rw-r--r--sh/profile.d/ls.sh34
1 files changed, 18 insertions, 16 deletions
diff --git a/sh/profile.d/ls.sh b/sh/profile.d/ls.sh
index a3cc84b7..0c3754e9 100644
--- a/sh/profile.d/ls.sh
+++ b/sh/profile.d/ls.sh
@@ -1,18 +1,20 @@
-# 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
- fi
- ;;
-esac
+ # 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
-# We're done parsing ls(1)'s --help output now
-unset -v ls_help
+ # 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
+ fi
+)