aboutsummaryrefslogtreecommitdiff
path: root/sh/profile.d/options.sh
blob: b4000e5d597c8112c3fbe72aab34aa9e5f5ac2c3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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 and step into it
    mkdir -p -- "$dir" || exit
    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

    # 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              \
    format             \
    hide-control-chars \
    human-readable     \
    time-style
)