File: typeset

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 (77 lines) | stat: -rw-r--r-- 2,824 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
# (C) 2010-2018 magicant

# Completion script for the "typeset" built-in command.
# Completion function "completion/typeset" is used for the "export", "local"
# and "readonly" built-ins as well.

function completion/typeset {

        typeset OPTIONS ARGOPT PREFIX
        OPTIONS=( #>#
        "p --print; print specified variables or functions"
        "X --unexport; cancel exportation of variables"
        "--help"
        ) #<#
        if [ "${WORDS[1]}" = "typeset" ]; then
                OPTIONS=("$OPTIONS" #>#
                "g --global; define global variables"
                ) #<#
        fi
        if [ "${WORDS[1]}" = "readonly" ] || [ "${WORDS[1]}" = "typeset" ]; then
                OPTIONS=("$OPTIONS" #>#
                "f --functions; define or print functions rather than variables"
                ) #<#
        fi
        if [ "${WORDS[1]}" != "export" ]; then
                OPTIONS=("$OPTIONS" #>#
                "x --export; export variables or print exported variables"
                ) #<#
        fi
        if [ "${WORDS[1]}" != "readonly" ]; then
                OPTIONS=("$OPTIONS" #>#
                "r --readonly; define or print read-only variables or functions"
                ) #<#
        fi

        command -f completion//parseoptions -es
        case $ARGOPT in
        (-)
                command -f completion//completeoptions
                ;;
        (*)
                typeset i=1 func=false
                while [ $i -le ${WORDS[#]} ]; do
                        case ${WORDS[i++]} in
                                (-f|--functions) func=true ;;
                                (--)             break ;;
                        esac
                done
                if $func; then
                        complete --function
                else
                        case $TARGETWORD in
                        (*=*:*)
                        # remove until the last colon after the first '=' and
                        # complete as a filename. If $word is
                        # PATH=/bin:/usr/bin:/u for example, we complete the
                        # filename /u
                                PREFIX=${TARGETWORD%"${${TARGETWORD#*=}##*:}"}
                                complete -T -P "$PREFIX" -S : -f
                                ;;
                        (*=*)
                        # remove until '=' and complete as a filename.
                                PREFIX=${TARGETWORD%"${TARGETWORD#*=}"}
                                complete -P "$PREFIX" -f
                                ;;
                        (*)
                                complete -T -S = -v
                                ;;
                        esac
                fi
                ;;
        esac

}


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