File: command

package info (click to toggle)
yash 2.60-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,152 kB
  • sloc: ansic: 34,578; makefile: 851; sh: 808; sed: 16
file content (105 lines) | stat: -rw-r--r-- 4,070 bytes parent folder | download
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# (C) 2010 magicant

# Completion script for the "command" built-in command.
# Completion function "completion/command" is used for the "type" built-in as
# well.

function completion/command {

        typeset OPTIONS ARGOPT PREFIX
        typeset COMMONOPTIONS VOPTIONS NOVOPTIONS
        COMMONOPTIONS=( #>#
        "b --builtin-command; execute or find a built-in command"
        "e --external-command; execute or find an external command"
        "f --function; execute or find a function"
        "p --standard-path; use the standard path in searching for a command"
        "--help"
        ) #<#
        VOPTIONS=( #>#
        "a --alias; find an alias"
        "k --keyword; find a shell keyword"
        ) #<#
        NOVOPTIONS=( #>#
        "v --identify; print the full path of a command"
        "V --verbose-identify; describe how a command is interpreted"
        ) #<#
        OPTIONS=("$COMMONOPTIONS" "$VOPTIONS" "$NOVOPTIONS")

        command -f completion//parseoptions

        typeset i=2 options=
        while [ $i -le ${WORDS[#]} ]; do
                case ${WORDS[i++]} in
                        (--)                    break ;;
                        (--help)                return ;;
                        (-a|--alias)            options=${options}a ;;
                        (-b|--builtin-command)  options=${options}b ;;
                        (-e|--external-command) options=${options}e ;;
                        (-f|--function)         options=${options}f ;;
                        (-k|--keyword)          options=${options}k ;;
                        (-p|--standard-path)    options=${options}p ;;
                        (-v|--identify)         options=${options}v ;;
                        (-V|--verbose-identify) options=${options}V ;;
                esac
        done
        WORDS=("${WORDS[i,-1]}")
        case $ARGOPT in
        (-)
                case $options in
                (*[vV]*)
                        OPTIONS=("$COMMONOPTIONS" "$VOPTIONS")
                        ;;
                (*)
                        OPTIONS=("$COMMONOPTIONS" "$NOVOPTIONS")
                        ;;
                esac
                command -f completion//completeoptions
                ;;
        (*)
                if
                        case $options in
                        (*[vV]*)
                                if [ -z "${options//[pvV]}" ]; then
                                        options=${options}abefk
                                fi
                                true
                                ;;
                        (*)
                                if [ -z "${options//p}" ]; then
                                        options=${options}be
                                fi
                                [ ${WORDS[#]} -eq 0 ]
                                ;;
                        esac
                then
                        # complete command name
                        case $options in (*a*)
                                complete --alias
                        esac
                        case $options in (*b*)
                                complete --builtin-command
                        esac
                        case $options in (*e*)
                                complete -T -S / -d
                                case $TARGETWORD in
                                        (*/*) complete --executable-file ;;
                                        (*  ) complete --external-command ;;
                                esac
                        esac
                        case $options in (*f*)
                                complete --function
                        esac
                        case $options in (*k*)
                                complete --keyword
                        esac
                else
                        # complete command argument
                        command -f completion//reexecute
                fi
                ;;
        esac

}


# vim: set ft=sh ts=8 sts=8 sw=8 et: