File: polkit-bash-completion.sh

package info (click to toggle)
policykit 0.9-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 5,984 kB
  • ctags: 1,593
  • sloc: ansic: 16,528; xml: 10,659; sh: 9,472; makefile: 633
file content (125 lines) | stat: -rw-r--r-- 4,911 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125

# Check for bash                                                                
[ -z "$BASH_VERSION" ] && return

####################################################################################################

__polkit_auth() {
    local IFS=$'\n'
    local cur="${COMP_WORDS[COMP_CWORD]}"

    case $COMP_CWORD in
        1)
            COMPREPLY=($(IFS=: compgen -S' ' -W "--obtain:--show-obtainable:--explicit:--explicit-detail:--grant:--block:--revoke:--user:--version:--help" -- $cur))
            ;;
        2)
	    case "${COMP_WORDS[1]}" in
                --obtain)   
                    COMPREPLY=($(compgen -W "$(polkit-auth --show-obtainable)" -- $cur))
                    ;;
                --revoke) 
                    COMPREPLY=($(compgen -W "$(polkit-auth --explicit)" -- $cur))
                    ;;
                --grant|--block)
                    COMPREPLY=($(compgen -W "$(polkit-action)" -- $cur))
                    ;;
                --user)   
                    COMPREPLY=($(compgen -u -- $cur))
                    ;;
            esac
            ;;
        3)
	    case "${COMP_WORDS[1]}" in
                --user)
                    COMPREPLY=($(IFS=: compgen -S' ' -W "--explicit:--explicit-detail:--grant:--block:--revoke" -- $cur))
                    ;;
                --grant|--block)
                    COMPREPLY=($(IFS=: compgen -S' ' -W "--constraint" -- $cur))
                    ;;
            esac
            ;;
        4)
	    case "${COMP_WORDS[3]}" in
                --revoke) 
	            case "${COMP_WORDS[1]}" in
                        --user)
                            local afou
                            # we may not be authorized to read the explicit auths for the given user..
                            afou=$(polkit-auth --user ${COMP_WORDS[2]} --explicit 2> /dev/null) 
                            if [ $? != 0 ] ; then
                                # .. so if that fails, fall back to showing all actions
                                afou=$(polkit-action)
                            fi
                            COMPREPLY=($(compgen -W "$afou" -- $cur))
                            ;;
                        *)
                            COMPREPLY=($(compgen -W "$(polkit-action)" -- $cur))
                            ;;
                    esac
                    ;;
                --grant|--block)
                    COMPREPLY=($(compgen -W "$(polkit-action)" -- $cur))
                    ;;
                --constraint)
                    COMPREPLY=($(IFS=: compgen -S' ' -W "local:active:exe\::selinux_context\:" -- $cur))
                    ;;
            esac
            ;;
        5)
	    case "${COMP_WORDS[3]}" in
                --grant|--block)
                    COMPREPLY=($(IFS=: compgen -S' ' -W "--constraint" -- $cur))
                    ;;
            esac
	    case "${COMP_WORDS[1]}" in
                --grant|--block)
                    COMPREPLY=($(IFS=: compgen -S' ' -W "--constraint" -- $cur))
                    ;;
            esac
            ;;
        *)
	    case "${COMP_WORDS[$(($COMP_CWORD - 1))]}" in
                --constraint)
                    COMPREPLY=($(IFS=: compgen -S' ' -W "local:active:exe\::selinux_context\:" -- $cur))
                    ;;
                *)
                    COMPREPLY=($(IFS=: compgen -S' ' -W "--constraint" -- $cur))
                    ;;
            esac
            ;;
    esac
}

####################################################################################################

__polkit_action() {
    local IFS=$'\n'
    local cur="${COMP_WORDS[COMP_CWORD]}"

    case $COMP_CWORD in
        1)
            COMPREPLY=($(IFS=: compgen -S' ' -W "--action:--reset-defaults:--set-defaults-any:--set-defaults-inactive:--set-defaults-active:--show-overrides:--version:--help" -- $cur))
            ;;
        2)
	    case "${COMP_WORDS[1]}" in
                --action|--set-defaults-any|--set-defaults-inactive|--set-defaults-active) 
                    COMPREPLY=($(compgen -W "$(polkit-action)" -- $cur))
                    ;;
                --reset-defaults) 
                    COMPREPLY=($(compgen -W "$(polkit-action --show-overrides)" -- $cur))
                    ;;
            esac
            ;;
        3)
	    case "${COMP_WORDS[1]}" in
                --set-defaults-any|--set-defaults-inactive|--set-defaults-active)
                    COMPREPLY=($(IFS=: compgen -S' ' -W "yes:no:auth_admin_one_shot:auth_admin:auth_admin_keep_session:auth_admin_keep_always:auth_self_one_shot:auth_self:auth_self_keep_session:auth_self_keep_always" -- $cur))
                    ;;
            esac
    esac
}

####################################################################################################

complete -o nospace -F __polkit_auth polkit-auth
complete -o nospace -F __polkit_action polkit-action