Refactoring udisksctl completion

- Apply formatting
- Use local variables instead of global variables
- Fix typos
- Update project URL
This commit is contained in:
Shohei YOSHIDA 2023-08-24 17:45:42 +09:00
parent 955ac75daf
commit 7494992bab
No known key found for this signature in database
GPG Key ID: C9A1BB11BB940CF2
1 changed files with 116 additions and 104 deletions

View File

@ -27,8 +27,7 @@
# Description
# -----------
#
# Completion script for udisksctl
# (https://cgit.freedesktop.org/udisks/tree/tools)
# Completion script for udisksctl (https://github.com/storaged-project/udisks)
#
# ------------------------------------------------------------------------------
# Authors
@ -48,8 +47,10 @@
# upstream bash completion. In the future one might consider rewriting using
# that. (but not sure how straight forward it would be to provide descriptions?)
#
# ------------------------------------------------------------------------------
_paths() {
(( $+functions[_udisksctl_paths] )) ||
_udisksctl_paths() {
local -a _path_list
for _path in $(_call_program paths "udisksctl complete \"udisksctl $words\" $CURSOR" | sed 's/:/\\:/g'); do
@ -59,13 +60,14 @@ _paths() {
_describe 'path' _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'
(( $+functions[_udisksctl_filesystems] )) ||
_udisksctl_filesystems() {
local -a _fs_types=(
'adfs' 'affs' 'autofs' 'btrfs' 'ceph' 'cifs' 'coda' 'coherent' 'cramfs'
'debugfs' 'devpts' 'efs' 'exfat' '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 type' _fs_types
@ -103,29 +105,29 @@ _udisksctl() {
case $words[1] in
info)
_arguments \
{-p,--object-path}'[specify object to get information about]:object path:_paths' \
{-b,--block-device}'[specify block device to get information about]:block device:_paths' \
{-d,--drive}'[specify drive to get information about]:drive:_paths' && ret=0
{-p,--object-path}'[specify object to get information about]:object path:_udisksctl_paths' \
{-b,--block-device}'[specify block device to get information about]:block device:_udisksctl_paths' \
{-d,--drive}'[specify drive to get information about]:drive:_udisksctl_paths' && ret=0
;;
mount)
_arguments \
{-p,--object-path}'[specify object to mount]:object path:_paths' \
{-b,--block-device}'[specify block device to mount]:block device:_paths' \
{-t,--filesystem-type}'[specify filesystem type to use]:fs type:_filesystems' \
{-p,--object-path}'[specify object to mount]:object path:_udisksctl_paths' \
{-b,--block-device}'[specify block device to mount]:block device:_udisksctl_paths' \
{-t,--filesystem-type}'[specify filesystem type to use]:fs type:_udisksctl_filesystems' \
{-o,--options}'[mount options]' \
"(--no-user-interaction)--no-user-interaction[don't authenticate the user if needed]" && ret=0
;;
unmount)
_arguments \
{-p,--object-path}'[object to unmount]:object path:_paths' \
{-b,--block-device}'[block device to unmount]:block device:_paths' \
{-p,--object-path}'[object to unmount]:object path:_udisksctl_paths' \
{-b,--block-device}'[block device to unmount]:block device:_udisksctl_paths' \
{-f,--force}'[force/lazy unmount]' \
"(--no-user-interaction)--no-user-interaction[don't auhenticate the user if needed]" && ret=0
"(--no-user-interaction)--no-user-interaction[don't authenticate the user if needed]" && ret=0
;;
unlock|lock)
_arguments \
{-p,--object-path}'[object to lock/unlock]:object path:_paths' \
{-b,--block-device}'[block device to lock/unlock]:block device:_paths' \
{-p,--object-path}'[object to lock/unlock]:object path:_udisksctl_paths' \
{-b,--block-device}'[block device to lock/unlock]:block device:_udisksctl_paths' \
"(--no-user-interaction)--no-user-interaction[don't authenticate the user if needed]" && ret=0
;;
loop-setup)
@ -138,27 +140,37 @@ _udisksctl() {
;;
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' \
{-p,--object-path}'[object for loop device to delete]:object path:_udisksctl_paths' \
{-b,--block-device}'[loop device to delete]:block device:_udisksctl_paths' \
"(--no-user-interaction)--no-user-interaction[don't authenticate the user if needed]" && ret=0
;;
power-off)
_arguments \
{-p,--object-path}'[object path for ATA device]:object path:_paths' \
{-b,--block-device}'[device file for ATA device]:block device:_paths' \
{-p,--object-path}'[object path for ATA device]:object path:_udisksctl_paths' \
{-b,--block-device}'[device file for ATA device]:block device:_udisksctl_paths' \
"(--no-user-interaction)--no-user-interaction[don't authenticate the user if needed]" && ret=0
;;
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' \
{-p,--object-path}'[object to get information about]:object path:_udisksctl_paths' \
{-b,--block-device}'[block device to get information about]:block device:_udisksctl_paths' \
"(--no-user-interaction)--no-user-interaction[don't authenticate the user if needed]" && ret=0
;;
esac
;;
esac
return ret
}
_udisksctl "$@"
# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et