From 01760c8d21440988932edeab193fa0f853abf125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Br=C3=B8nner?= Date: Sun, 25 Dec 2016 08:30:44 +0100 Subject: [PATCH 1/4] Completion for 'udisksctl' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Salvaged from rejected/ignored patch to upstream by Damir Jelić (poljar) [1]. License is assumed to be gpl2 since it was submitted as a patch to udisks [2]. I tried contacting poljar, but the email address is no longer active. [1] https://lists.freedesktop.org/archives/devkit-devel/2014-February/001554.html [2] https://cgit.freedesktop.org/udisks/tree/tools --- src/_udisksctl | 135 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 src/_udisksctl diff --git a/src/_udisksctl b/src/_udisksctl new file mode 100644 index 0000000..745c7d3 --- /dev/null +++ b/src/_udisksctl @@ -0,0 +1,135 @@ +#compdef udisksctl +# +# ------------------------------------------------------------------------------ +# Copyright (C) 2007-2011 David Zeuthen +# Copyright (C) 2007-2011 Red Hat, Inc. +# All Rights Reserved. +# +# The source code for the udisks daemon and command-line tools are +# licensed to you under the GNU General Public License. Either version 2 +# of the License, or (at your option) any later version. +# +# https://www.gnu.org/licenses/old-licenses/gpl-2.0.html +# +# ------------------------------------------------------------------------------ +# Description +# ----------- +# +# Completion script for udisksctl +# (https://cgit.freedesktop.org/udisks/tree/tools) +# +# ------------------------------------------------------------------------------ +# Authors +# ------- +# +# * Damir Jelić [1] +# +# [1] https://lists.freedesktop.org/archives/devkit-devel/2014-February/001554.html +# + + +_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 bytes into file]:offset in bytes:' \ + {-s,--size}'[Limit size to 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 "$@" From bb32e9eb90d2edf695b1c6447b321fc016a396d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Br=C3=B8nner?= Date: Tue, 27 Dec 2016 07:25:40 +0100 Subject: [PATCH 2/4] udisksctl: add new/missing command --- src/_udisksctl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/_udisksctl b/src/_udisksctl index 745c7d3..e0efe54 100644 --- a/src/_udisksctl +++ b/src/_udisksctl @@ -23,6 +23,7 @@ # ------- # # * Damir Jelić [1] +# * Ole Jørgen Brønner (minor additions) # # [1] https://lists.freedesktop.org/archives/devkit-devel/2014-February/001554.html # @@ -72,6 +73,7 @@ _udisksctl() { 'lock: Lock an encrypted device' 'loop-setup: Set-up a loop device' 'loop-delete: Delete a loop device' + 'power-off: Safely power off a drive' 'smart-simulate: Set SMART data for a drive' ) _describe -t commands 'udisksctl commands' commands @@ -120,6 +122,12 @@ _udisksctl() { {-b,--block-device}'[Loop device to delete]:block device:_paths' \ '(--no-user-interaction)--no-user-interaction[Do not authenticate the user if needed]' \ ;; + power-off) + _arguments \ + {-p,--object-path}'[Object path for ATA device]:object path:_paths' \ + {-b,--block-device}'[Device file for ATA devic]: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' \ From 688562c9878e4ab5ee864a68dba917380c4506ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Br=C3=B8nner?= Date: Tue, 27 Dec 2016 07:33:33 +0100 Subject: [PATCH 3/4] udisksctl: Change license to MIT Fits in a header, less restrictive etc. See https://github.com/zsh-users/zsh-completions/pull/483 --- src/_udisksctl | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/_udisksctl b/src/_udisksctl index e0efe54..fb7c83e 100644 --- a/src/_udisksctl +++ b/src/_udisksctl @@ -1,15 +1,27 @@ #compdef udisksctl # # ------------------------------------------------------------------------------ -# Copyright (C) 2007-2011 David Zeuthen -# Copyright (C) 2007-2011 Red Hat, Inc. -# All Rights Reserved. -# -# The source code for the udisks daemon and command-line tools are -# licensed to you under the GNU General Public License. Either version 2 -# of the License, or (at your option) any later version. +# The MIT License # -# https://www.gnu.org/licenses/old-licenses/gpl-2.0.html +# Copyright 2014 Damir Jelić +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. # # ------------------------------------------------------------------------------ # Description From 3ae23b8996c08e3f1229b893e7308a56c1a99221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Br=C3=B8nner?= Date: Tue, 27 Dec 2016 07:46:49 +0100 Subject: [PATCH 4/4] udisksctl: Add some notes about the upstream bash completions --- src/_udisksctl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/_udisksctl b/src/_udisksctl index fb7c83e..267c4af 100644 --- a/src/_udisksctl +++ b/src/_udisksctl @@ -39,7 +39,15 @@ # # [1] https://lists.freedesktop.org/archives/devkit-devel/2014-February/001554.html # - +# ------------------------------------------------------------------------------ +# Notes +# ----- +# +# udisksctl actually provide built-in support for completion: It accepts an +# special command 'complete' that returns completeions. That is what drives the +# upstream bash completion. In the future one might condsider rewriting using +# that. (but not sure how straight forward it would be to provide descriptions?) +# _paths() { local -a _path_list