summaryrefslogtreecommitdiff
blob: 37f8d0d1e80342facfbd5de865f129626ba99a8f (plain)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
commit afb4535accaa08e20050a7b2d508d884b02f45a0
Author: Saleem Abdulrasool <compnerd@compnerd.org>
Date:   Mon Nov 19 15:35:03 2007 -0800

    add zsh completion and optionalize bash and zsh completion
    
    Signed-off-by: Saleem Abdulrasool <compnerd@compnerd.org>

diff --git a/configure.in b/configure.in
index 2fdb935..a9ea35a 100644
--- a/configure.in
+++ b/configure.in
@@ -495,6 +495,21 @@ AC_DEFINE_UNQUOTED(PAM_FILE_INCLUDE_PASSWORD, "$PAM_FILE_INCLUDE_PASSWORD", [pam
 AC_DEFINE_UNQUOTED(PAM_FILE_INCLUDE_SESSION, "$PAM_FILE_INCLUDE_SESSION", [pam file session])
 
 # ********************
+# Shell Completion
+# ********************
+
+AC_ARG_WITH([bash-completion],
+            AC_HELP_STRING([--with-bash-completion],[Install bash completion scripts]),,
+            [with_bash_completion=yes])
+
+AC_ARG_WITH([zsh-completion],
+            AC_HELP_STRING([--with-zsh-completion],[Install zsh completion scripts]),,
+            [with_zsh_completion=no])
+
+AM_CONDITIONAL([WITH_BASH_COMPLETION], test x"$with_bash_completion" != x"no")
+AM_CONDITIONAL([WITH_ZSH_COMPLETION], test x"$with_zsh_completion" != x"no")
+
+# ********************
 # Internationalisation
 # ********************
 
diff --git a/tools/Makefile.am b/tools/Makefile.am
index a76e9fc..0449e12 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -25,10 +25,17 @@ polkit_auth_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ $(top_builddir)/src/polkit/libpolkit
 polkit_action_SOURCES = polkit-action.c
 polkit_action_LDADD = $(top_builddir)/src/polkit/libpolkit.la
 
+if WITH_BASH_COMPLETION
 profiledir = $(sysconfdir)/profile.d
 profile_SCRIPTS = polkit-bash-completion.sh
+endif
 
-EXTRA_DIST = $(profile_SCRIPTS)
+if WITH_ZSH_COMPLETION
+zshcompletiondir = $(DESTDIR)$(datadir)/zsh/site-functions
+zshcompletion_SCRIPTS = _polkit _polkit_auth _polkit_action
+endif
+
+EXTRA_DIST = polkit-bash-completion.sh _polkit _polkit_auth _polkit_action
 
 clean-local :
 	rm -f *~ polkit-reload-config
diff --git a/tools/_polkit b/tools/_polkit
new file mode 100644
index 0000000..bc7bdac
--- /dev/null
+++ b/tools/_polkit
@@ -0,0 +1,54 @@
+#autoload
+
+# vim: set et sw=3 sts=3 ts=3 ft=zsh:
+# ZSH Completion for polkit-auth
+# Written by Saleem Abdulrasool <compnerd@compnerd.org>
+# Usage: _polkit actions|constraints|authorization|overriden-actions|obtainable-actions|authorized-actions
+
+_polkit_actions() {
+   local actions
+   actions=( $(polkit-action) )
+   compadd "$@" -k actions
+}
+
+_polkit_constraints() {
+   local constraints
+   constraints=( local active local+active )
+   compadd "$@" -k constraints
+}
+
+_polkit_authorization() {
+   local authorization
+   authorization=( 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 yes )
+   compadd "$@" -k authorization
+}
+
+_polkit_overriden_actions() {
+   local overrides
+   overrides=( $(polkit-action --show-overrides) )
+   compadd "$@" -k overrides
+}
+
+_polkit_obtainable_actions() {
+   local actions
+   actions=( $(polkit-auth --show-obtainable) )
+   compadd "$@" -k actions
+}
+
+_polkit_authorized_actions() {
+   local actions
+   actions=( $(polkit-auth --explicit) )
+   compadd "$@" -k actions
+}
+
+_polkit() {
+   local command="$argv[$#]"
+
+   [[ "$command" == (actions|constraints|authorization|overriden-actions|obtainable-actions|authorized-actions) ]] || {
+      _message "unknown command: $command"
+   }
+
+   _polkit_${command/-/_}
+}
+
+_polkit "$@"
diff --git a/tools/_polkit_action b/tools/_polkit_action
new file mode 100644
index 0000000..7ec7365
--- /dev/null
+++ b/tools/_polkit_action
@@ -0,0 +1,24 @@
+#compdef polkit-action
+
+# vim: set et sw=3 sts=3 ts=3 ft=zsh:
+# ZSH Completion for polkit-action
+# Written by Saleem Abdulrasool <compnerd@compnerd.org>
+
+_polkit_action() {
+   local arguments
+
+   arguments=(
+      "(-)--action[Show detailed information about a specific action]:action:_polkit actions"
+      "(-)--reset-defaults[Reset the defaults for the specified action]:Overridden Action:_polkit overriden-actions"
+      "(-)--show-overrides[List actions where the defaults are overridden]"
+      "(-)--set-defaults-any[Override the any stanza for an action]:Action:_polkit _actions:Authorization:_polkit authorization"
+      "(-)--set-defaults-inactive[Override the inactive stanza for an action]:Action:polkit _actions:Authorization:_polkit authorization"
+      "(-)--set-defaults-active[Override the active stanza for an action]:Action:polkit _actions:Authorization:_polkit authorization"
+      "(-)--version[Display program version]"
+      "(-)--help[Display program help]"
+   )
+
+   _arguments $arguments
+}
+
+_polkit_action "$@"
diff --git a/tools/_polkit_auth b/tools/_polkit_auth
new file mode 100644
index 0000000..e70f1a0
--- /dev/null
+++ b/tools/_polkit_auth
@@ -0,0 +1,50 @@
+#compdef polkit-auth
+
+# vim: set et sw=3 sts=3 ts=3 ft=zsh:
+# ZSH Completion for polkit-auth
+# Written by Saleem Abdulrasool <compnerd@compnerd.org>
+
+_polkit_auth() {
+   local arguments action_arguments user_arguments grant_arguments
+   local commands actions grant=0
+
+   commands=( --show-obtainable --version --help )
+   actions=( --obtain --explicit --explicit-detail --grant --revoke )
+
+   for (( i = 0 ; i < ${#words[@]} ; i++ )) ; do
+      if [[ "${words[$i]##--#}" == "grant" ]] ; then
+         grant=1
+         break
+      fi
+   done
+
+   arguments=(
+      '(-)--show-obtainable[Show all actions that can be obtained via authentication]'
+      '(-)--version[Show version and exit]'
+      '(-)--help[Show help information]'
+   )
+
+   action_arguments=(
+      "($commands $actions)--obtain[Attempt to obtain authorization to do an action]:Obtainable Actions:_polkit obtainable-actions"
+      "($commands $actions)--explicit[Show explicit authorizations]"
+      "($commands $actions)--explicit-detail[Show detailed information about explicit authorizations]"
+      "($commands $actions)--grant[Grant an authorization for an action]:Obtainable Actions:_polkit actions"
+      "($commands $actions)--revoke[Revoke all authorization for an action]:Authorized Actions:_polkit authorized-actions"
+   )
+
+   user_arguments=(
+      "($commands)--user[The user the authorization applies to]:User:_users"
+   )
+
+   grant_arguments=(
+      "($commands)--constraint[Optional constraints on the granted authorization]:Constraint:_polkit constraints"
+   )
+
+   if [[ grant -eq 1 ]] ; then
+      _arguments $arguments $user_arguments $action_arguments $grant_arguments
+   else
+      _arguments $arguments $user_arguments $action_arguments
+   fi
+}
+
+_polkit_auth "$@"