Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] completion for systat(1) and vmstat(8)



Add completion for vmstat and systat, i used _default 
as a fallback for OSes that doesn't match.
---
 Completion/BSD/Command/_systat  | 87 +++++++++++++++++++++++++++++++++++++++++
 Completion/Unix/Command/_vmstat | 83 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 170 insertions(+)
 create mode 100644 Completion/BSD/Command/_systat
 create mode 100644 Completion/Unix/Command/_vmstat

diff --git a/Completion/BSD/Command/_systat b/Completion/BSD/Command/_systat
new file mode 100644
index 0000000..e45b949
--- /dev/null
+++ b/Completion/BSD/Command/_systat
@@ -0,0 +1,87 @@
+#compdef systat
+
+local -a screens args
+case $OSTYPE in
+  freebsd*)
+    local pre=-
+    screens=(
+      'pigs:processes consuming the most CPU time'
+      icmp{6,}':ICMP statistics'
+      ip{6,}':IP and UDP statistics'
+      'tcp:TCP statistics'
+      'iostat:processor and disk statistics'
+      'swap:swap space statistics'
+      'vmstat:virtual memory statistics'
+      'netstat:network connection statistics'
+      'ifstat:network traffic statistics'
+    ) 
+  ;;
+  openbsd*)
+    screens=(
+      'buckets:kernel malloc(9) bucket statistics'
+      'cpu:per CPU, usage statistics'
+      'ifstat:interface statistics'
+      'iostat:disk throughput statistics'
+      'malloc:malloc(9) type statistics'
+      'mbufs:mbuf usage statistics'
+      'netstat:network connection statistics'
+      'nfsclient:NFS client statistics'
+      'nfsserver:NFS server statistics'
+      'pf:pf(4) filter statistics'
+      'pigs:processes consuming the most CPU time'
+      'pool:pool(9) statistics'
+      'queues:pf(4) queue statistics'
+      'rules:pf(4) rule statistics'
+      'sensors:display hardware sensors values'
+      'states:pf(4) states statistics'
+      'swap:swap space usage'
+      'vmstat:virtual memory statistics'
+    )
+    opts=(
+      '-a[display all lines]'
+      '-B[raw, non-interactive mode (two screen updates)]'
+      '-b[raw, non-interactive mode (one screen update)]'
+      '-d[exit after `count'\'' updates]:count'
+      '-i[interactive mode]'
+      '-N[resolve network addresses to names]'
+      '-n[do not resolve network addresses to names]'
+      '-s[screen refresh interval]:refresh interval (seconds)'
+      '-w[maximum width of output in raw mode]:width'
+    )
+  ;;
+  netbsd*)
+    screens=(
+      'all:cycle through all displays'
+      'bufcache:filesystem buffer statistics'
+      'df:disk usage statistics'
+      'inet.icmp:ICMP statistics'
+      'inet.ip:IPv4 and UDP statistics'
+      'inet.tcp:TCP statistics'
+      'inet.tcpsyn:TCP ``syncache'\'\'' statistics'
+      'inet6.ip6:IPv6 statistics'
+      'iostat:disk throughput statistics'
+      'mbufs:mbuf usage statistics'
+      'netstat:network connection statistics'
+      'pigs:processes consuming the most CPU time'
+      'ps:``ps -aux'\'\'' in a loop'
+      'swap:swap space usage'
+      'syscall:per system call statistics'
+      'vmstat:virtual memory statistics'
+    )
+    opts=(
+      '-M[alternative source to extract values from]:core:_files'
+      '-N[alternative source to extract the name list from]:system:_files'
+      '-n[do not resolve IP addresses]'
+      '-w[refresh interval]:refresh interval'
+      '-t[the amount of refreshes for each screen in '\''all'\'' display mode]:turns'
+    )
+esac
+
+if (( $#screens )); then
+  _arguments -M 'r:|.=* r:|=*' : $opts \
+    '1:systat(1) displays:(( ${pre}$^screens ))' \
+    '2:refresh interval'
+  return
+fi
+
+_default
diff --git a/Completion/Unix/Command/_vmstat b/Completion/Unix/Command/_vmstat
new file mode 100644
index 0000000..9227deb
--- /dev/null
+++ b/Completion/Unix/Command/_vmstat
@@ -0,0 +1,83 @@
+#compdef vmstat
+
+local -a specs
+case $OSTYPE in
+  *linux*)
+    specs=(
+      '(-a --active)'{-a,--active}'[active/inactive memory]'
+      '(-f --forks)'{-f,--forks}'[number of forks since boot]'
+      '(-m --slabs)'{-m,--slabs}'[slabinfo]'
+      '(-n --one-header)'{-n,--one-header}'[do not redisplay header]'
+      '(-s --stats)'{-s,--stats}'[event counter statistics]'
+      '(-d --disk)'{-d,--disk}'[disk statistics]'
+      '(-D --disk-sum)'{-D,--disk-sum}'[summarize disk statistics]'
+      '(-p --partition)'{-p,--partition}'[partition specific statistics]:partition:_files'
+      '(-S --unit)'{-S+,--unit}'[define display unit]:unit prefix:(( k\:1000 K\:1024 m\:1000000 M\:1048576 ))'
+      '(-w --wide)'{-w,--wide}'[wide output]'
+      '(-t --timestamp)'{-t,--timestamp}'[show timestamp]'
+      '1:delay' '2:count'
+    )
+  ;;
+  freebsd*)
+    specs=(
+      '-a[include statistics about all interrupts]'
+      '-c[number of times to refresh the display]:count'
+      '-f[report on the number fork syscalls since boot and pages of virtual memory for each]'
+      '-h[human readable memory columns output]'
+      '-H[scriptable memory columns output]'
+      '-i[report the number of interrupts taken by devices since boot]'
+      '-M[source file to extract values associated with the name list from]:core:_files'
+      '-N[source file to extract the name list from]:system:_files'
+      '-m[report on the usage of kernel dynamic memory allocated using malloc(9) by type]'
+      '-n[change the maximum number of disks to display]:number of disks to display'
+      '-P[report per-cpu system/user/idle cpu statistics]'
+      '-p[specify which types of devices to display]: :->devices'
+      '-s[display the contents of the SUM structure]:sum'
+      '-w[delay N seconds between each display]:delay'
+      '-z[report on memory used by the kernel zone allocator, uma(9), by zone]'
+      '*:disks:_files'
+    )
+  ;;
+  openbsd*)
+    specs=(
+      '-c[number of times to refresh the display]:count'
+      '-f[report on the number fork syscalls since boot and pages of virtual memory for each]'
+      '-i[report the number of interrupts taken by devices since boot]'
+      '-M[source file to extract values associated with the name list from]:core:_files'
+      '-m[report usage of kernel dynamic memory listed first by size of allocation then type of usage]'
+      '-N[source file to extract the name list from]:system:_files'
+      '-s[display the contents of the UVMEXP structure]:uvmexp'
+      '-t[report on the number of page in and page reclaims since boot]'
+      '-v[print more verbose information]'
+      '-w[delay N seconds between each display]:delay'
+      '-z[include statistics about all interrupts]'
+      '*:disks:_files'
+    )
+  ;;
+esac
+
+if (( $#specs )); then
+  local curcontext=$curcontext state state_descr line ret=1
+  typeset -A {opt,val}_args
+
+  _arguments -C -s -w -A '-*' : "$specs[@]" && ret=0
+
+  if [[ $state == devices ]]; then
+    local -a types
+    types=( 
+      'da[direct access devices]' 'sa[sequential access devices]'
+      'printer[printers]' 'proc[processor devices]'
+      'worm[write once read multiple devices]' 'cd[CD devices]'
+      'scanner[scanner devices]' 'optical[optical memory devices]'
+      'changer[medium changer devices]' 'comm[communication devices]'
+      'array[storage array devices]' 'enclosure[enclosure services devices]'
+      'floppy[floppy devices]' 'IDE[Integrated Drive Electronics devices]'
+      'SCSI[Small Computer System Interface devices]'
+      'other[any other device interface]' 'pass[passthrough devices]'
+    )
+    _values -C -s , 'device type' "$types[@]" && ret=0
+  fi
+  return ret
+fi
+
+_default
-- 
2.5.0



Messages sorted by: Reverse Date, Date, Thread, Author