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

PATCH: update util-linux completions



This updates completions for some of the util-linux tools to 2.30.1.
losetup seems to have been changed around a lot yet again.
Completion for wipefs is new.

For some things that come with util-linux, there are other
implementations around, last for instance. It would be good to handle
such cases better.

Oliver

diff --git a/Completion/Linux/Command/_chrt b/Completion/Linux/Command/_chrt
index f82ec8b81..6789b66cf 100644
--- a/Completion/Linux/Command/_chrt
+++ b/Completion/Linux/Command/_chrt
@@ -1,61 +1,68 @@
 #compdef chrt
 
-local context state line
+local curcontext="$curcontext" cmd="$words[1]" ret=1
+local -a state line expl
 typeset -A opt_args
 
-_arguments \
+_arguments -C -s -S -A "-*" \
+  '(H -a --all-tasks)'{-a,--all-tasks}'[operate on all tasks (threads) for a given pid]' \
+  '(H)'{-v,--verbose}'[display status information]' \
+  '(H)'{-p,--pid}'[interpret args as process ID]' \
+  '(H -R --reset-on-fork -b --batch -d --deadline -i --idle -o --other)'{-R,--reset-on-fork}'[set SCHED_RESET_ON_FORK for FIFO or RR]' \
+  '(H)*::command or priority:->cmd_or_prio' \
+  + 'H' \
+  '(* -)'{-m,--max}'[show minimum and maximum valid priorities, then exit]' \
   '(* -)'{-h,--help}'[display usage information]' \
   '(* -)'{-V,--version}'[output version information]' \
-  {-v,--verbose}'[display status information]' \
-  {-p,--pid}'[interpret args as process ID]' \
-  '(-b --batch -f --fifo -o --other -r --rr)'{-b,--batch}'[set scheduling policy to SCHED_BATCH]' \
-  '(-b --batch -f --fifo -o --other -r --rr)'{-f,--fifo}'[set scheduling policy to SCHED_FIFO]' \
-  '(-b --batch -f --fifo -o --other -r --rr)'{-o,--other}'[set policy scheduling policy to SCHED_OTHER]' \
-  '(-b --batch -f --fifo -o --other -r --rr)'{-r,--rr}'[set scheduling policy to SCHED_RR]' \
-  '(* -)'{-m,--max}'[show minimum and maximum valid priorities, then exit]' \
-  '*::command or priority:->cmd_or_prio' \
-  && return 0
+  + 'dline' \
+  '(H -T --sched-runtime -b --batch -f --fifo -i --idle -o --other -r --rr)'{-T,--sched-runtime}'[runtime parameter for DEADLINE]' \
+  '(H -P --sched-period -b --batch -f --fifo -i --idle -o --other -r --rr)'{-P,--sched-period}'[period parameter for DEADLINE]' \
+  '(H -D --sched-deadline -b --batch -f --fifo -i --idle -o --other -r --rr)'{-D,--sched-deadline}'[deadline parameter for DEADLINE]' \
+  + '(policy)' \
+  '(H dline -R --reset-on-fork)'{-b,--batch}'[set scheduling policy to SCHED_BATCH]' \
+  '(H -R --reset-on-fork)'{-d,--deadline}'[set scheduling policy to SCHED_DEADLINE]' \
+  '(H dline)'{-f,--fifo}'[set scheduling policy to SCHED_FIFO]' \
+  '(H dline -R --reset-on-fork)'{-i,--idle}'[set scheduling policy to SCHED_IDLE]' \
+  '(H dline -R --reset-on-fork)'{-o,--other}'[set scheduling policy to SCHED_OTHER]' \
+  '(H dline)'{-r,--rr}'[set scheduling policy to SCHED_RR (default)]' && ret=0
 
 _chrt_priority()
 {
-    local ty
-    if (( $+opt_args[-b] || $+opt_args[--batch] ))
-    then
-        ty=BATCH
-    elif (( $+opt_args[-f] || $+opt_args[--fifo] ))
-    then
-        ty=FIFO
-    elif (( $+opt_args[-o] || $+opt_args[--other] ))
-    then
-        ty=OTHER
-    else
-        ty=RR
-    fi
-    local range
-    range=${${"$(_call_program priorities chrt --max)"#*SCHED_$ty*: }%$'\n'*}
-    if [[ $range = 0/0 ]]
-    then
-        compadd 0
-    else
-        _message -e priority "priority in the range $range"
-    fi
+  local ty
+  [[ -prefix - ]] && return 1
+  if (( $+opt_args[policy--b] || $+opt_args[policy---batch] )); then
+    ty=BATCH
+  elif (( $+opt_args[policy--f] || $+opt_args[policy---fifo] )); then
+    ty=FIFO
+  elif (( $+opt_args[policy--o] || $+opt_args[policy---other] )); then
+    ty=OTHER
+  else
+    ty=RR
+  fi
+  local range
+  range=${${(M)${(f)"$(_call_program priorities $cmd --max)"}:#*_${ty}*}#*: }
+  if [[ $range = 0/0 ]]; then
+    _wanted priorites expl 'priority' compadd 0
+  else
+    _message -e priorities "priority (range $range)"
+  fi
 }
 
 if (( $+opt_args[-p] || $+opt_args[--pid] ))
 then
-    if [[ $CURRENT -eq 1 ]]
-    then
-        _alternative \
-          'priority:priority:_chrt_priority' \
-          'processes:process IDs:_pids'
-    else
-        _pids
-    fi
-elif [[ $CURRENT -eq 1 ]]
-then
-    _chrt_priority
+  if (( CURRENT == 1 )); then
+    _alternative \
+      'priority:priority:_chrt_priority' \
+      'processes:process IDs:_pids' && ret=0
+  else
+    _pids && ret=0
+  fi
+elif (( CURRENT == 1 )); then
+  _chrt_priority && ret=0
 else
-    shift words
-    (( CURRENT-- ))
-    _normal
+  shift words
+  (( CURRENT-- ))
+  _normal && ret=0
 fi
+
+return ret
diff --git a/Completion/Linux/Command/_ionice b/Completion/Linux/Command/_ionice
index a3d49ec99..d64f1c496 100644
--- a/Completion/Linux/Command/_ionice
+++ b/Completion/Linux/Command/_ionice
@@ -1,12 +1,35 @@
 #compdef ionice
 
-_arguments \
-  '(* -)-h[display usage information]' \
-  '(*)-p[interpret args as process ID]:pid:_pids' \
-  '-c+[scheduling class]:class:(( 1\:realtime 2\:best-effort 3\:idle ))' \
-  '-n+[scheduling class priority]:class-priority:((
+local curcontext="$curcontext" state line expl ret=1
+local -A opt_args
+
+_arguments -C -s -S \
+  '(H -c --class)'{-c+,--class=}'[scheduling class]:class:((0\:none 1\:realtime 2\:best-effort 3\:idle))' \
+  '(H -m --classdata)'{-n+,--classdata=}'[scheduling class priority]:class-priority:((
     0\:high\ priority
     {6..1}\:
     7\:low\ priority
   ))' \
-  '*::command:_normal'
+  '(H -t --ignore)'{-t,--ignore}'[ignore failures]' \
+  '(H)*:: :->args' \
+  + 'H' \
+  '(- *)'{-V,--version}'[display version information]' \
+  '(- *)'{-h,--help}'[display help information]' \
+  + '(args)' \
+  '(H)'{-p-,--pid=-}'[interpret args as process ID]::process id:_pids' \
+  '(H)'{-P-,--pgid=-}'[specify process group IDs]::process group' \
+  '(H)'{-u-,--uid=-}'[act on running process owned by specified users]::user id' && ret=0
+
+if [[ -n $state ]]; then
+  if (( $+opt_args[args--p] || $+opt_args[args---pid] )); then
+    _pids && ret=0
+  elif (( $+opt_args[args--P] || $+opt_args[args---pgid] )); then
+    _message -e pgids 'process group'
+  elif (( $+opt_args[args--u] || $+opt_args[args---uid] )); then
+    _message -e uids 'user id'
+  else
+    _normal && ret=0
+  fi
+fi
+
+return ret
diff --git a/Completion/Linux/Command/_losetup b/Completion/Linux/Command/_losetup
index 359a9e0ea..05ef7c56c 100644
--- a/Completion/Linux/Command/_losetup
+++ b/Completion/Linux/Command/_losetup
@@ -1,28 +1,44 @@
-#compdef losetup
-# based on util-linux 2.26.2
+#lcompdef losetup -value-,LOOPDEV_DEBUG,-default-
 
-_arguments -S -A '-*' \
-  '(-l --list)'{-l,--list}'[list currently used loop devices]' \
-  '(-n --noheadings)'{-n,--noheadings}'[do not print heading for --list output]' \
-  '(-d --delete --detach -o --offset -a --all)'{-o,--offset}'+[specify data start is offset]:offset (bytes)' \
-  '(-O --output)'{-O,--output}'[specify columns to be printed with --list]:column: _values -s , column name sizelimit offset autoclear ro back-file' \
-  '(-P --partscan)'{-P,--partscan}'[scan the partition table of newly created loop devices]' \
-  '--raw[raw output format]' \
-  '(-r --read-only)'{-r,--read-only}'[set up a read-only loop device]' \
+if [[ $service = *LOOPDEV_DEBUG* ]]; then
+  local expl
+  _wanted values expl value compadd all
+  return
+fi
+
+local device offset
+
+device='1:device:_files -g "/dev/loop<->"'
+offset=( {-o,--offset}'+[specify data start is offset]:offset (bytes)' )
+
+_arguments -s -S \
+  - '(H)'\
+  {-V,--version}'[display version information]' \
+  {-h,--help}'[display help]' \
+  - 'info' \
   '(-v --verbose)'{-v,--verbose}'[verbose mode]' \
-  '(-V --version)'{-V,--version}'[display version information]' \
-  '(-h --help)'{-h,--help}'[display help]' \
-  '1:device:_files -g "/dev/loop<->"' \
-  '(-d --delete --detach)2:file:_files' \
-  - '(set1)' \
-  '(-o --offset)'{-a,--all}'[show the status of all loop devices]' \
-  - '(set2)' \
-  {-c,--set-capacity}'[reread  the size of the file associated with the loop device]' \
-  - '(set3)' \
-  '(- 2)'{--delete,--detach,-d}'[detach from specified loop device]' \
-  - '(set4)' \
-  '(-D --detach-all)'{-D,--detach-all}'[detach all associated loop devices]' \
-  - '(set5)' \
-  {-f,--find}'[find the first unused loop device]' \
-  - '(set6)' \
-  {-j,--associated}'[show the status of all loop devices associated with an file]: : _files'
+  '(-o --offset -a --all)'{-a,--all}'[show the status of all loop devices]' \
+  '(-O --output)'{-O+,--output=}'[specify columns to be printed with --list]:column:_sequence -s , compadd - name autoclear back-file back-ino back-maj\:min maj\:min offset partscan ro sizelimit dio' \
+  '(-J --json --raw -O --output -n --noheadings)'{-J,--json}'[use JSON --list output format]' \
+  '(-l --list)'{-l,--list}'[list currently used loop devices]' \
+  '(-J --json)--raw[raw output format]' \
+  '(-n --noheadings -J --json)'{-n,--noheadings}"[don't print headings in --list output]" \
+  - '(resize)' \
+  {-c,--set-capacity}'[reread the size of the file associated with the loop device]' \
+  - 'detach' \
+  '(-)'{--delete,--detach,-d}'[detach from specified loop device]' \
+  "$device" \
+  - '(detach-all)' \
+  {-D,--detach-all}'[detach all associated loop devices]' \
+  - 'create' \
+  '--direct-io[open backing file with O_DIRECT]::enable:(on off)' \
+  '(-f --find 2)'{-f,--find}'[find the first unused loop device]' \
+  '(-L --nooverlap)'{-L,--nooverlap}'[avoid possible conflict between devices]' \
+  '(-P --partscan)'{-P,--partscan}'[scan the partition table of newly created loop devices]' \
+  '--sizelimit[limit device to specified size]:size (bytes)' \
+  '--show[print device name after setup]' \
+  '(-r --read-only)'{-r,--read-only}'[set up a read-only loop device]' \
+  '1:file:_files' \
+  - 'assoc' \
+  '(-j --associated)'{-j,--associated}'[show the status of all loop devices associated with an file]:associated file:_files' \
+  "(-f)$device"
diff --git a/Completion/Linux/Command/_wipefs b/Completion/Linux/Command/_wipefs
new file mode 100644
index 000000000..6e8507978
--- /dev/null
+++ b/Completion/Linux/Command/_wipefs
@@ -0,0 +1,15 @@
+#compdef wipefs
+
+_arguments -s -S \
+  '(H -a --all)'{-a,--all}'[wipe all magic strings]' \
+  '(H -b --backup)'{-b,--backup}'[create a signature backup in $HOME]' \
+  '(H -f --force)'{-f,--force}'[force erasure]' \
+  '(H -n --no-act)'{-n,--no-act}'[do everything except the actual write() call]' \
+  '(H -o --offset)'{-o+,--offset=}'[specify offset to erase]:offset (bytes)' \
+  '(H -p --parsable)'{-p,--parsable}'[print out in parsable instead of printable format]' \
+  '(H -q --quiet)'{-q,--quiet}'[suppress output messages]' \
+  '(H -t --types)'{-t+,--types=}'[limit the set of filesystem, RAIDs or partition tables]:type:_file_systems' \
+  '(H)*:disk device:_files -g "*(-%)" -P / -W /' \
+  + '(H)' \
+  '(- *)'{-h,--help}'[display help information]' \
+  '(- *)'{-V,--version}'[display version information]'

.



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