aboutsummaryrefslogtreecommitdiff
path: root/sh/profile.d
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-01-25 14:51:53 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-01-25 14:52:41 +1300
commitff0041f1416098cbd90d4374c72e8cb6ff9c22b3 (patch)
treeadcae04131666d30764f1ea6ebaba3362452f3f7 /sh/profile.d
parent1200846f20de92c3bf8f88f4230ccbb9ab047969 (diff)
downloaddotfiles-ff0041f1416098cbd90d4374c72e8cb6ff9c22b3.tar.gz
dotfiles-ff0041f1416098cbd90d4374c72e8cb6ff9c22b3.zip
Avoid a fork in options detection
Diffstat (limited to 'sh/profile.d')
-rw-r--r--sh/profile.d/options.sh17
1 files changed, 9 insertions, 8 deletions
diff --git a/sh/profile.d/options.sh b/sh/profile.d/options.sh
index 345888d0..a668a360 100644
--- a/sh/profile.d/options.sh
+++ b/sh/profile.d/options.sh
@@ -1,10 +1,13 @@
# Cache the options available to certain programs. Run all this in a subshell
# (none of its state needs to endure in the session)
(
-options() (
+options() {
# Check or create the directory to cache the options
+ # Shift the program name off; remaining arguments are the options to check
dir=$HOME/.cache/$1
+ prog=$1
+ shift
# Directory already exists; bail out
[ -d "$dir" ] && exit
@@ -14,18 +17,16 @@ options() (
cd -- "$dir" || exit
# Write the program'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
+ # This probably only works with GNU tools in general
+ "$prog" --help </dev/null >help 2>/dev/null || exit
- # Iterate through some useful options and create files to show they're
- # available if found in the help output
+ # Iterate through remaining arguments (desired options), creating files to
+ # show they're available if found in the help output
for opt ; do
command -p grep -q -- '[^[:alnum:]]--'"$opt"'[^[:alnum:]]' help &&
touch -- "$opt"
done
-)
+}
# Cache options for bc(1)
options bc \