File: __help__

package info (click to toggle)
zplug 2.4.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,068 kB
  • sloc: sh: 1,504; awk: 235; makefile: 26
file content (89 lines) | stat: -rw-r--r-- 1,947 bytes parent folder | download | duplicates (4)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env zsh
# Description:
#   Display the help message

local    f  arg
local -a fs args

local -A opts cmds
local    obj opt cmd
local -i max=0

while (( $# > 0 ))
do
    arg="$1"
    case "$arg" in
        -*|--*)
            break
            ;;
        "")
            ;;
        *)
            fs=( "$(echo $ZPLUG_HOME/doc/man/man(1|5)/(zplug-|)${arg}.(1|5)(N))" )
            # Non-existing man page
            if [[ $fs[1] == "" ]]; then
                __zplug::io::print::f \
                    --die \
                    --zplug \
                    "$arg: no such subcommand or tag\n"
                return 1
            fi
            # List all hits pages
            for f in "${fs[@]}"
            do
                if [[ -f $f ]]; then
                    args+=( "$f" )
                fi
            done
            ;;
    esac
    shift
done

if (( $#args > 0 )); then
    man "${args[@]}"
    return $status
fi

# Measure max length
{
    cmds=( "${(kv)_zplug_commands[@]}" )
    for opt in "${(k)_zplug_options[@]}"
    do
        opts[--$opt]="$_zplug_options[$opt]"
    done

    for obj in "${(k)cmds[@]}" "${(k)opts[@]}"
    do
        if (( $#obj > $max )); then
            max=$#obj
        fi
    done
}

# Help message format
{
    printf "usage: zplug [OPTIONS] [COMMANDS [options] [args]]\n"
    printf "  zplug is a next-generation plugin manager for zsh\n"

    for obj in \
        OPTIONS  "${(k)opts[@]}" \
        COMMANDS "${(k)cmds[@]}"; do \
        case "$obj" in
            OPTIONS | COMMANDS)
                printf "\n$obj:\n"
                ;;
            *)
                desc="(None)"
                [[ -n $opts[$obj] ]] && desc="$opts[$obj]"
                [[ -n $cmds[$obj] ]] && desc="$cmds[$obj]"
                printf "  %-${max}s    %s\n" \
                    "$obj" \
                    "$desc"
                ;;
        esac
    done
    printf "\n"
} >&2

return 1