about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArseny Maslennikov <ar@cs.msu.ru>2021-03-21 16:01:29 +0300
committerOliver Kiddle <opk@zsh.org>2021-03-28 12:27:12 +0200
commit14709db6d6009c198b1b90f2c7b87f65194527a5 (patch)
treeda263b81edcf99cf98af739d5341b33c015efddc
parent42de9318f1bd05873eb850a830d30af13bc07415 (diff)
downloadzsh-14709db6d6009c198b1b90f2c7b87f65194527a5.tar.gz
zsh-14709db6d6009c198b1b90f2c7b87f65194527a5.tar.xz
zsh-14709db6d6009c198b1b90f2c7b87f65194527a5.zip
48212: Introduce new completion for Linux task capabilities
-rw-r--r--ChangeLog3
-rw-r--r--Completion/Linux/Type/_capabilities65
2 files changed, 68 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 6fb01eab5..2bbf0afd5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2021-03-28  Oliver Kiddle  <opk@zsh.org>
 
+	* Arseny Maslennikov: 48212: Completion/Linux/Type/_capabilities:
+	Introduce new completion for Linux task capabilities
+
 	* Štěpán Němec: 48231: Completion/Unix/Command/_git:
 	add missing --pretty formats and improve descriptions
 
diff --git a/Completion/Linux/Type/_capabilities b/Completion/Linux/Type/_capabilities
new file mode 100644
index 000000000..8cb31878f
--- /dev/null
+++ b/Completion/Linux/Type/_capabilities
@@ -0,0 +1,65 @@
+#autoload
+
+# This function completes POSIX capabilities for Linux.
+# Many command line utilities expect different syntax to encode various kinds
+# of capability names or sets, so this function tries to be as generic as
+# possible. It accepts compadd options to allow variations on the exact
+# generated completion matches.
+#
+# Usage examples:
+#
+# Complete full capability names:
+#   _capabilities -p cap_
+# Sort the completion list by capability number:
+#   _capabilities -o nosort
+
+# 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:]]+CAP_//; s/[[:space:]]+[0-9]+$//' | tr '[[:upper:]]' '[[:lower:]]'
+local -a caplist=(
+  chown
+  dac_override
+  dac_read_search
+  fowner
+  fsetid
+  kill
+  setgid
+  setuid
+  setpcap
+  linux_immutable
+  net_bind_service
+  net_broadcast
+  net_admin
+  net_raw
+  ipc_lock
+  ipc_owner
+  sys_module
+  sys_rawio
+  sys_chroot
+  sys_ptrace
+  sys_pacct
+  sys_admin
+  sys_boot
+  sys_nice
+  sys_resource
+  sys_time
+  sys_tty_config
+  mknod
+  lease
+  audit_write
+  audit_control
+  setfcap
+  mac_override
+  mac_admin
+  syslog
+  wake_alarm
+  block_suspend
+  audit_read
+  perfmon
+  bpf
+  checkpoint_restore
+)
+local -a expl
+
+_description capabilities expl "Linux capability"
+compadd "${(@)expl}" "$@" -a - caplist