diff options
Diffstat (limited to 'sh/profile.d/options.sh')
-rw-r--r-- | sh/profile.d/options.sh | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/sh/profile.d/options.sh b/sh/profile.d/options.sh index aa7e9ace..89b5d245 100644 --- a/sh/profile.d/options.sh +++ b/sh/profile.d/options.sh @@ -1,31 +1,32 @@ # 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 - dir=$HOME/.cache/$1 + # Shift the program name off; remaining arguments are the options to check + dir=$HOME/.cache/sh/opt/$1 + prog=$1 + shift # Directory already exists; bail out - [ -d "$dir" ] && exit + [ -d "$dir" ] && return # Create the directory and step into it - command -p mkdir -p -- "$dir" || exit - cd -- "$dir" || exit + command -p mkdir -p -- "$dir" || return + cd -- "$dir" || return # 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 || return - # 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 \ @@ -46,12 +47,9 @@ options grep \ # Cache options for ls(1) options ls \ - almost-all \ - block-size \ - classify \ - color \ - format \ - hide-control-chars \ - human-readable \ + almost-all \ + block-size \ + color \ + human-readable \ time-style ) |