aboutsummaryrefslogtreecommitdiffstats
path: root/src/_rfkill
blob: 1c88133454be2183550897ff6aec09ca9bf0bfa8 (plain) (blame)
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
#compdef rfkill
# ------------------------------------------------------------------------------
# Copyright (c) 2014 Vincent Bernat <bernat@luffy.cx>
# 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 <bernat@luffy.cx>
#
# ------------------------------------------------------------------------------

_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