From 21768854d87f1f9d95ded77ef1d45081b8a238c1 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Tue, 26 Aug 2014 17:38:52 +0200 Subject: [PATCH] Completion for `rfkill` --- src/_rfkill | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/_rfkill diff --git a/src/_rfkill b/src/_rfkill new file mode 100644 index 0000000..1c88133 --- /dev/null +++ b/src/_rfkill @@ -0,0 +1,102 @@ +#compdef rfkill +# ------------------------------------------------------------------------------ +# Copyright (c) 2014 Vincent Bernat +# Copyright (c) 2014 Github zsh-users - http://github.com/zsh-users +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# ------------------------------------------------------------------------------ +# Description +# ----------- +# +# Completion script for rfkill (http://wireless.kernel.org/en/users/Documentation/rfkill) +# +# ------------------------------------------------------------------------------ +# Authors +# ------- +# +# * Vincent Bernat +# +# ------------------------------------------------------------------------------ + +_rfkill_types() { + declare -a devicetypes + devicetypes=(all + "wifi:Wireless LAN" "wlan:Wireless LAN" + "bluetooth:Bluetooth" + "uwb:Ultrawide Band" + "ultrawideband:Ultrawide Band" + "wimax:Wimax" + "wwan:3G" + "gps:GPS" + "fm:FM Radio" + "nfc:NFC") + _describe -t device-types "device types" devicetypes +} + +_rfkill_devices() { + declare -a devices + devices=(${(M)${(f)"$(rfkill list)"}:#[0-9]*}) + _rfkill_types + _describe -t devices "devices" devices +} + +_rfkill_commands () { + declare -a subcommands + subcommands=(help event list block unblock) + _describe -t rfkill-commands "rfkill command" subcommands +} + +_rfkill_subcommand () { + case "$words[1]" in + (help|event) + ;; + (list) + _arguments ':types:_rfkill_types' + ;; + (block|unblock) + _arguments ':device:_rfkill_devices' + ;; + (*) + _message 'Unknown subcommand' + esac +} + +_rfkill () { + local curcontext="$curcontext" state line + typeset -A opt_args + + _arguments -C \ + '--version[get version]:' \ + '(-): :->command' \ + '(-)*:: :->arguments' + + case $state in + (command) + _rfkill_commands + ;; + (arguments) + curcontext=${curcontext%:*:*}:rfkill-$words[1]: + _rfkill_subcommand + ;; + esac +} + +_rfkill "$@" + +# 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