From: poljar (Damir Jelić) <poljari...@gmail.com>

This patch adds and install optionally udisksctl completion for zsh.

Signed-off-by: poljar (Damir Jelić) <pol...@poljar.org>
---
 configure.ac                |   7 +++
 data/Makefile.am            |   8 ++++
 data/completions/_udisksctl | 107 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 122 insertions(+)
 create mode 100644 data/completions/_udisksctl

diff --git a/configure.ac b/configure.ac
index 7224fce..50afd2d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -196,6 +196,13 @@ AC_SUBST([GETTEXT_PACKAGE])
 AM_GLIB_GNU_GETTEXT
 AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE],["$GETTEXT_PACKAGE"],[gettext domain])
 
+# zsh completion
+#
+AC_ARG_WITH([zsh-completion],
+             AS_HELP_STRING([--with-zsh-completion],[Install zsh completion 
scripts]),,
+             [with_zsh_completion=no])
+AM_CONDITIONAL([WITH_ZSH_COMPLETION], test x"$with_zsh_completion" != x"no")
+
 # Generate
 #
 
diff --git a/data/Makefile.am b/data/Makefile.am
index 0921698..bef5c80 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -37,6 +37,13 @@ completions_DATA =                                   \
        completions/udisksctl                           \
        $(NULL)
 
+if WITH_ZSH_COMPLETION
+zshcompletionsdir = $(datadir)/zsh/site-functions
+zshcompletions_DATA =                                  \
+       completions/_udisksctl                          \
+       $(NULL)
+endif
+
 @INTLTOOL_POLICY_RULE@
 
 EXTRA_DIST =                                           \
@@ -47,6 +54,7 @@ EXTRA_DIST =                                          \
        $(dbusconf_in_files)                            \
        $(polkit_in_files)                              \
        $(completions_DATA)                             \
+       $(zshcompletions_DATA)                          \
        $(NULL)
 
 clean-local :
diff --git a/data/completions/_udisksctl b/data/completions/_udisksctl
new file mode 100644
index 0000000..3726429
--- /dev/null
+++ b/data/completions/_udisksctl
@@ -0,0 +1,107 @@
+#compdef udisksctl
+
+_paths() {
+    local -a _path_list
+
+    for _path in $(_call_program paths "udisksctl complete \"udisksctl 
$words\" $CURSOR"); do
+        _path_list+=$_path
+    done
+
+    _describe 'paths' _path_list
+}
+
+_filesystems() {
+    _fs_types=(
+        'adfs' 'affs' 'autofs' 'cifs' 'coda' 'coherent' 'cramfs' 'debugfs' 
'devpts'
+        'efs' 'ext' 'ext2' 'ext3' 'ext4' 'hfs' 'hfsplus' 'hpfs' 'iso9660' 
'jfs' 'minix'
+        'msdos' 'ncpfs' 'nfs' 'nfs4' 'ntfs' 'proc' 'qnx4' 'ramfs' 'reiserfs' 
'romfs'
+        'squashfs' 'smbfs' 'sysv' 'tmpfs' 'ubifs' 'udf' 'ufs' 'umsdos' 'usbfs' 
'vfat'
+        'xenix' 'xfs' 'xiafs'
+    )
+
+    _describe 'file system types' _fs_types
+}
+
+_udisksctl() {
+    typeset -A opt_args
+    local curcontext="$curcontext" state line
+
+    _arguments -C \
+        '1:udisksctl commands:->cmds' \
+        '*:: :->cmd_args' \
+
+    case $state in
+        cmds)
+            local commands; commands=(
+                'help: Show help'
+                'info: Show info about an object'
+                'dump: Show info about all object'
+                'status: Shows high-level status'
+                'monitor: Monitor changes to objects'
+                'mount: Mount a filesystem'
+                'unmount: Unmount a filesystem'
+                'unlock: Unlock an encrypted device'
+                'lock: Lock an encrypted device'
+                'loop-setup: Set-up a loop device'
+                'loop-delete: Delete a loop device'
+                'smart-simulate: Set SMART data for a drive'
+            )
+            _describe -t commands 'udisksctl commands' commands
+        ;;
+
+        cmd_args)
+            case $words[1] in
+                info)
+                    _arguments \
+                        {-p,--object-path}'[Object to get information 
about]:object path:_paths' \
+                        {-b,--block-device}'[Block device to get information 
about]:block device:_paths' \
+                        {-d,--drive}'[Drive to get information 
about]:drives:_paths' \
+                ;;
+                mount)
+                    _arguments \
+                        {-p,--object-path}'[Object to mount]:object 
path:_paths' \
+                        {-b,--block-device}'[Block device to mount]:block 
device:_paths' \
+                        {-t,--filesystem-type}'[Filesystem type to use]:fs 
type:_filesystems' \
+                        {-o,--options}'[Mount options]' \
+                        '(--no-user-interaction)--no-user-interaction[Do not 
authenticate the user if needed]' \
+                ;;
+                unmount)
+                    _arguments \
+                        {-p,--object-path}'[Object to unmount]:object 
path:_paths' \
+                        {-b,--block-device}'[Block device to unmount]:block 
device:_paths' \
+                        {-f,--force}'[Force/lazy unmount]' \
+                        '(--no-user-interaction)--no-user-interaction[Do not 
authenticate the user if needed]' \
+                ;;
+                unlock|lock)
+                    _arguments \
+                        {-p,--object-path}'[Object to lock/unlock]:object 
path:_paths' \
+                        {-b,--block-device}'[Block device to 
lock/unlock]:block device:_paths' \
+                        '(--no-user-interaction)--no-user-interaction[Do not 
authenticate the user if needed]' \
+                ;;
+                loop-setup)
+                    _arguments \
+                        {-f,--file}'[File to set-up a loop device 
for]:files:_files' \
+                        {-r,--read-only}'[Setup read-only device]' \
+                        {-o,--offset}'[Start at <num> bytes into file]:offset 
in bytes:' \
+                        {-s,--size}'[Limit size to <num> bytes]:limit in 
bytes:' \
+                        '(--no-user-interaction)--no-user-interaction[Do not 
authenticate the user if needed]' \
+                ;;
+                loop-delete)
+                    _arguments \
+                        {-p,--object-path}'[Object for loop device to 
delete]:object path:_paths' \
+                        {-b,--block-device}'[Loop device to delete]:block 
device:_paths' \
+                        '(--no-user-interaction)--no-user-interaction[Do not 
authenticate the user if needed]' \
+                ;;
+                smart-simulate)
+                    _arguments \
+                        {-f,--file}'[File with libatasmart blob]:files:_files' 
\
+                        {-p,--object-path}'[Object to get information 
about]:object path:_paths' \
+                        {-b,--block-device}'[Block device to get information 
about]:block device:_paths' \
+                        '(--no-user-interaction)--no-user-interaction[Do not 
authenticate the user if needed]' \
+                ;;
+            esac
+        ;;
+    esac
+}
+
+_udisksctl "$@"
-- 
1.8.5.3

_______________________________________________
devkit-devel mailing list
devkit-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/devkit-devel

Reply via email to