aboutsummaryrefslogtreecommitdiff
path: root/sh/profile.d/options.sh
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-21 23:02:35 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-21 23:02:35 +1200
commitcc7a77804b12d86251e71303d1887b48c43f13b2 (patch)
treebf3747118cc0b96e78b2a615aea70bb71c54fc20 /sh/profile.d/options.sh
parentDistill/fix keychain handling a bit (diff)
downloaddotfiles-cc7a77804b12d86251e71303d1887b48c43f13b2.tar.gz
dotfiles-cc7a77804b12d86251e71303d1887b48c43f13b2.zip
Consolidate ed,bc,grep,ls.sh into one function
Diffstat (limited to 'sh/profile.d/options.sh')
-rw-r--r--sh/profile.d/options.sh55
1 files changed, 55 insertions, 0 deletions
diff --git a/sh/profile.d/options.sh b/sh/profile.d/options.sh
new file mode 100644
index 00000000..aa6bea06
--- /dev/null
+++ b/sh/profile.d/options.sh
@@ -0,0 +1,55 @@
+# Cache the options available to certain programs. Run all this in a subshell
+# (none of its state needs to endure in the session)
+(
+options() { (
+
+ # Check or create the directory to cache the options
+ dir=$HOME/.cache/$1
+
+ # Directory already exists; bail out
+ [ -d "$dir" ] && exit
+
+ # Create the directory
+ mkdir -p -- "$dir" || exit
+ cd -- "$dir" || exit
+
+ # Write grep(1)'s --help output to a file, even if it's empty
+ "$1" --help </dev/null >help 2>/dev/null || exit
+
+ # Shift the program name off; remaining arguments are the options to check
+ shift
+
+ # Iterate through some useful options and create files to show they're
+ # available if found in the help output
+ for opt ; do
+ grep -q -- '[^[:alnum:]]--'"$opt"'[^[:alnum:]]' help &&
+ touch -- "$opt"
+ done
+) ; }
+
+# Cache options for bc(1)
+options bc \
+ quiet
+
+# Cache options for ed(1)
+options ed \
+ verbose
+
+# Cache options for grep(1)
+options grep \
+ binary-files \
+ color \
+ devices \
+ directories \
+ exclude \
+ exclude-dir
+
+# Cache options for ls(1)
+options ls \
+ almost-all \
+ block-size \
+ classify \
+ color \
+ human-readable \
+ time-style
+)