zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH 1/2] Introduce new completion for Linux task capabilities
@ 2021-02-26  7:55 Arseny Maslennikov
  2021-02-26  7:55 ` [PATCH 2/2] Introduce new completion for setpriv(1) on Linux Arseny Maslennikov
  2021-02-26 15:50 ` [PATCH 1/2] Introduce new completion for Linux task capabilities Daniel Shahaf
  0 siblings, 2 replies; 8+ messages in thread
From: Arseny Maslennikov @ 2021-02-26  7:55 UTC (permalink / raw)
  To: zsh-workers; +Cc: Arseny Maslennikov

This is intended for use on Linux-based systems only.

The next patch introduces a completion for setpriv(1), which actively
uses _capability_names. As for _capabilities, there are currently no
users of this function, but I believe some utilities that handle caps
may actually want to use it (neither setpriv(1) nor setcap/getcap(8),
for instance, want to offer the cap names themselves as completion
results; instead they want to prefix each name or a comma-separated
sequence of names), and if not yet — it is still available to be
manually compdeffed.
---
 Completion/Linux/Type/_capabilities     | 10 ++++++++++
 Completion/Linux/Type/_capability_names | 20 ++++++++++++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 Completion/Linux/Type/_capabilities
 create mode 100644 Completion/Linux/Type/_capability_names

diff --git a/Completion/Linux/Type/_capabilities b/Completion/Linux/Type/_capabilities
new file mode 100644
index 000000000..5a97aa335
--- /dev/null
+++ b/Completion/Linux/Type/_capabilities
@@ -0,0 +1,10 @@
+#autoload
+
+if [[ $OSTYPE != linux* ]]; then
+    _default; return
+fi
+
+local -a expl matches
+
+_capability_names matches
+_wanted capabilities expl "Linux capabilities" compadd "$@" -a - matches
diff --git a/Completion/Linux/Type/_capability_names b/Completion/Linux/Type/_capability_names
new file mode 100644
index 000000000..a2243b716
--- /dev/null
+++ b/Completion/Linux/Type/_capability_names
@@ -0,0 +1,20 @@
+#autoload
+
+_capability_names() {
+  # Stores an array of Linux task capability names under a parameter
+  # named by the first argument.
+
+  if [[ $OSTYPE != linux* ]]; then
+      _default; return
+  fi
+
+  # The list of Linux capabilities is taken from include/uapi/linux/capability.h
+  # and subject to the following pipe filter:
+  # grep 'define CAP' | sed -r 's/^[[:space:]]*#define[[:space:]]+//; s/[[:space:]]+[0-9]+$//' | tr '[[:upper:]]' '[[:lower:]]'
+  local -a C=(
+    cap_chown cap_dac_override cap_dac_read_search cap_fowner cap_fsetid cap_kill cap_setgid cap_setuid cap_setpcap cap_linux_immutable cap_net_bind_service cap_net_broadcast cap_net_admin cap_net_raw cap_ipc_lock cap_ipc_owner cap_sys_module cap_sys_rawio cap_sys_chroot cap_sys_ptrace cap_sys_pacct cap_sys_admin cap_sys_boot cap_sys_nice cap_sys_resource cap_sys_time cap_sys_tty_config cap_mknod cap_lease cap_audit_write cap_audit_control cap_setfcap cap_mac_override cap_mac_admin cap_syslog cap_wake_alarm cap_block_suspend cap_audit_read cap_perfmon cap_bpf cap_checkpoint_restore
+  )
+  set -A "$1" "${(@)C}"
+}
+
+_capability_names "$@"
-- 
2.30.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-03-21 12:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-26  7:55 [PATCH 1/2] Introduce new completion for Linux task capabilities Arseny Maslennikov
2021-02-26  7:55 ` [PATCH 2/2] Introduce new completion for setpriv(1) on Linux Arseny Maslennikov
2021-02-26 15:50 ` [PATCH 1/2] Introduce new completion for Linux task capabilities Daniel Shahaf
2021-02-26 17:01   ` Arseny Maslennikov
2021-02-27 12:03     ` Oliver Kiddle
2021-03-20  2:43       ` Lawrence Velázquez
2021-03-21 12:54         ` Arseny Maslennikov
2021-03-21 12:54       ` Arseny Maslennikov

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).