about summary refs log tree commit diff
path: root/Completion
diff options
context:
space:
mode:
Diffstat (limited to 'Completion')
-rw-r--r--Completion/Unix/Command/_top177
1 files changed, 125 insertions, 52 deletions
diff --git a/Completion/Unix/Command/_top b/Completion/Unix/Command/_top
index 0259c236a..8f81e9526 100644
--- a/Completion/Unix/Command/_top
+++ b/Completion/Unix/Command/_top
@@ -1,12 +1,16 @@
 #compdef top
 
-local specs fields
+local curcontext="$curcontext" state state_descr line ret=1
+local -A opt_args
+local -a specs fields order opts
+
+opts=( -s -w -C )
 
 case $OSTYPE in
   *linux*)
     fields=(
       '%CPU:CPU usage' '%MEM:memory usage (res)' 'CGROUPS:control groups'
-      'CODE:code size' 'COMMAND:Commane name/line' 'DATA:data + stack size'
+      'CODE:code size' 'COMMAND:Command name/line' 'DATA:data + stack size'
       'ENVIRON:environment variables' 'Flags:task flags' 'GID:group id'
       'GROUP:group name' 'NI:nice value' 'P:last used CPU (SMP)'
       'PGRP:process group id' 'PID:process id' 'PPID:parent pid' 'PR:priority'
@@ -24,78 +28,147 @@ case $OSTYPE in
       'nsUTS:UTS namespace' 'vMj:major page fault count delta'
       'vMn:minor page fault count delta'
     )
+    order=( '+:descending (default)' '-:ascending' )
     specs=(
-      '(-v -h)-'{h,v}'[show version and usage]'
+      '(-)-'{h,v}'[show version and usage]'
       '-b[batch mode]'
       '-c[command line/program name toggle]'
-      '-d[delay time interval]:interval'
+      '-d+[delay time interval]:interval'
       '-H[threads mode operation]'
       '-i[idle process toggle]'
-      '-n[number of iterations]:number of iterations'
-      '-o[override sort field]:fieldname:(( $fields ))'
+      '-n+[number of iterations]:number of iterations'
+      '-o+[override sort field]:fieldname:->sortkey'
       '-O[output field names]'
-      '*-p[monitor pids]: :_pids'
+      '*-p+[monitor pids]: :_sequence -s , _pids'
       '-s[secure mode operation]'
       '-S[cumulative time toggle]'
-      '(-U)-u[effective user filter mode]: :_users'
-      '(-u)-U[user filter mode]: :_users'
-      '-w[output width override]:number'
+      '(-U)-u+[effective user filter mode]: :_users'
+      '(-u)-U+[user filter mode]: :_users'
+      '-w+[output width override]::number'
     );;
-  freebsd*)
+  freebsd*|openbsd*)
+    fields=( cpu size res time pri pid )
     specs=(
-      '-C[CPU display mode]'
-      '-S[show system processes]'
-      '-a[display command names via argv]'
       '-b[batch mode]'
+      '-d+[show only specified number of displays then exit]:count:'
       '-H[display individual threads]'
-      '-i[interactive mode]'
       '-I[do not display idle processes]'
+      '-i[interactive mode]'
+      '-n[non-interactive mode (identical to batch mode)]'
+      '-o+[sort process display by the specified field]:field:( $fields )'
+      '-q[renice top to -20]'
+      '-S[show system processes]'
+      '-s+[specify delay interval]:seconds:'
+      '-u[do not translate uid to name]'
+      '1: :_guard "^-*" "number of processes to display"'
+    );|
+  freebsd*)
+    fields+=( threads total read write fault vcsw ivcsw jid )
+    specs+=(
+      '-C[CPU display mode]'
+      '-a[display command names via argv]'
       '-j[display the jail ID]'
       '-t[do not display the top process]'
-      '-m+[statistic type]:type:(( cpu\:default io ))'
-      '-n[non-interactive mode]'
+      '-m+[specify statistic type]:type:(( cpu\:default io ))'
       '-P[per-cpu CPU usage statistics]'
-      '-q[renice top to -20]'
-      '-u[do not translate uid to name]'
-      '-v[write version number]'
-      '-z[no not display system idle process]'
-      '-d+[number of iterations]:count:'
-      '-s+[set delay interval]:interval:'
-      '-o+[sort process display by field]:field:(
-        cpu size res time pri threads total read 
-        write fault vcsw ivcsw jid pid
-      )'
-      '-J+[show processes owned by jail]:jail:_jails -0'
-      '-U+[show processes owned by username]: :_users'
-      '1: : _message "top number of processes"'
+      '(1 -)-v[write version number and exit]'
+      '-z[do not display system idle process]'
+      '-J+[show processes owned by the specified jail]:jail:_jails -0'
+      '-U+[show processes owned by the specified username]: :_users'
     );;
   openbsd*)
-    specs=(
+    fields+=( command )
+    specs+=(
       '-1[combine CPU statistic into one line]'
-      '-b[batch mode]'
-      '-C[show command arguments as well and process name]'
-      '-d[number of iterations]:number of iterations'
-      '-g[filter processes by string]:string'
-      '-H[display process threads]'
-      '-I[do not display idle processes]'
-      '-i[interactive mode]'
-      '-n[non-interactive mode]'
-      '-o[sort display by field]:field:(
-        cpu size res time pri pid command
-      )'
-      '-p[filter by pid]: :_pids'
-      '-q[renice top to -20]'
-      '-S[show system processes]'
-      '-s[delay time interval]:interval'
-      '-U[filter processes by user]: :_users -M "L\:|-="'
-      '-u[do not map uid to usernames]'
-      '1: : _message "top number of processes"'
+      '-C[show command arguments as well as process name]'
+      '-g+[filter processes by the specified string]:string'
+      '-p+[filter by the specified pid]: :_pids'
+      '-U+[filter processes by the specified user]: :_users -M "L\:|-="'
+    );;
+  darwin*)
+    local -a modes
+    opts=( -C )   # no option stacking
+    modes=(
+      'a:count events cumulatively'
+      'd:count events relative to the previous sample'
+      'e:count events using absolute counters'
+      'n:non-event mode (default)'
+    )
+    fields=(
+      'pid:process id'
+      'command:command name'
+      'cpu:CPU usage'
+      'cpu_me:CPU time charged to me by other processes'
+      'cpu_others:CPU time charged to other processes by me'
+      'csw:number of context switches'
+      'time:execution time'
+      {threads,th}':number of threads'
+      {ports,prt}':number of Mach ports'
+      {mregion,mreg,reg}':number of memory regions'
+      'mem:internal memory size'
+      'rprvt:resident private address space size'
+      'purg:purgeable memory size'
+      'vsize:total memory size'
+      'vprvt:private address space size'
+      'kprvt:private kernel memory size'
+      'kshrd:shared kernel memory size'
+      'pgrp:process group id'
+      'ppid:parent process id'
+      {state,pstate}':process state'
+      'uid:user id'
+      {wq,'#wq',workqueue}':workqueue total/running'
+      {faults,fault}':number of page faults'
+      {cow,cow_faults}':copy-on-write faults'
+      {user,username}':username'
+      'msgsent:total number of Mach messages sent'
+      'msgrecv:total number of Mach messages received'
+      'sysbsd:total BSD syscalls'
+      'sysmach:total Mach syscalls'
+      'pageins:total pageins'
+      'boosts:number of boosts held by the process'
+    )
+    order=( '-:descending (default)' '+:ascending' )
+    specs=(
+      '-a[count events cumulatively]'
+      '-c[set event counting mode]:mode:(( $modes ))'
+      '-d[count events relative to the previous sample]'
+      '-e[count events using absolute counters]'
+      '-F[do not calculate statistics on shared libraries]'
+      '-f[calculate statistics on shared libraries]'
+      '(-)-h[print usage information and exit]'
+      '-i+[specify interval between samples for -f option]:interval'
+      '-l+[logging mode. output specified number of samples periodically]:number of samples'
+      '-ncols[output specified number of columns in logging mode]:number of columns'
+      '-n+[only display up to the specified number of processes]:number of processes:'
+      '-O+[specify the secondary sort key]:key:->sortkey'
+      '-o+[specify the primary sort key]:key:->sortkey'
+      '-R[do not traverse and report memory object map for each process]'
+      '-r[traverse and report memory object map for each process]'
+      '-S[display global statistics for swap and purgeable memory]'
+      '-s[set the delay between update]:number of seconds'
+      '-stats[only display the specified fields]:list of fields:->fieldlist'
+      '*-pid[only display the specified process]:pid:_pids'
+      {-user,-U+}'[only display processes owned by the specified user]:user:_users'
+      '-u[same as -o cpu -O time]'
     );;
 esac
 
-if (( $#specs )); then
-  _arguments -s -w : "$specs[@]"
+if (( $#specs == 0 )); then
+  _default
   return
 fi
 
-_default
+_arguments $opts : "$specs[@]" && ret=0
+
+case $state in
+  (sortkey)
+    compset -P '(+|-)' && order=()
+    _alternative 'sort-orders:sort order:(( $order ))' \
+	'sort-keys:sort key:(( $fields ))' && ret=0
+    ;;
+  (fieldlist)
+    _sequence -s , _describe -t fields 'field' fields && ret=0
+    ;;
+esac
+
+return ret