zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: completion for a few more coreutils things
@ 2017-10-06 22:16 Oliver Kiddle
  2017-10-10  6:18 ` Jun T
  0 siblings, 1 reply; 7+ messages in thread
From: Oliver Kiddle @ 2017-10-06 22:16 UTC (permalink / raw)
  To: Zsh workers

There's still a surprising number of utilities in GNU coreutils for
which we still don't have a completion function. For many, a completion
wouldn't be much use - there's lots of variants of sum, commands that
don't really have any options, things that aren't so relevant today
(e.g. pr) and a few oddities that aren't so well known (e.g. ptx).

However coreutils tend to be the sort of thing you'd expect to have a
completion for so I've picked out a few which seemed useful or for which
_gnu_generic doesn't do a great job:
  expand, mv, numfmt, seq, split, stdbuf, timeout

There's also minor tweaks to _cp and _unexpand that I noticed in the
process.

As usual, I've also handled Solaris and the usual cluster of BSDs.

Oliver

diff --git a/Completion/Unix/Command/_cp b/Completion/Unix/Command/_cp
index 5c3f37983..88750b330 100644
--- a/Completion/Unix/Command/_cp
+++ b/Completion/Unix/Command/_cp
@@ -55,7 +55,7 @@ else
     'netbsd*' "-N[don't copy file flags]" \
     '(darwin|dragonfly|freebsd|netbsd)*' '-a[archive mode, same as -RpP]' \
     '(dragonfly|freebsd)*' '-l[link files instead of copying]' \
-    '(darwin|dragonfly|freebsd|netbsd)*' '-v[show file names as they are copied]' \
+    '(darwin|dragonfly|*bsd)*' '-v[show file names as they are copied]' \
     'darwin*' "-X[don't copy extended attributes or resource forks]" \
     '(dragonfly|freebsd)*' "-x[don't traverse file systems]" \
     'freebsd<10->.*' '-s[make symbolic links instead of copies of non-directories]'
diff --git a/Completion/Unix/Command/_expand b/Completion/Unix/Command/_expand
index e69de29bb..3f297dce2 100644
--- a/Completion/Unix/Command/_expand
+++ b/Completion/Unix/Command/_expand
@@ -0,0 +1,16 @@
+#compdef expand gexpand
+
+local -a args
+
+if _pick_variant gnu=GNU unix --version; then
+  args=(
+    '(-i --initial --help)'{-i,--initial}"[don't convert tabs after non blanks]"
+    '(-t --tabs --version)'{-t+,--tabs=}'[specify tab width]:list of tab positions'
+    '(* -)--help[display usage information]'
+    '(* -)--version[output version information]'
+  )
+else
+  args=( -A "-*" '(-t --tabs)'{-t+,--tabs=}'[specify tab width]:list of tab positions' )
+fi
+
+_arguments -s -S "$args[@]" '*:file:_files'
diff --git a/Completion/Unix/Command/_mv b/Completion/Unix/Command/_mv
index e69de29bb..3592efee6 100644
--- a/Completion/Unix/Command/_mv
+++ b/Completion/Unix/Command/_mv
@@ -0,0 +1,42 @@
+#compdef mv gmv
+
+local args
+if _pick_variant gnu=GNU unix --version; then
+  args=(
+    '(-b --backup -n --no-clobber)--backup=[make a backup of each existing destination file]: : _values "backup type"
+      {none,off}"[never make backups]"
+      {numbered,t}"[make numbered backups]"
+      {existing,nil}"[numbered backups, if they already exist]"
+      {simple,never}"[always make simple backups]"'
+    '(-b --backup -n --no-clobber)-b[make a backup of each existing destination file]'
+    '(-f --force -i --interactive -n --no-clobber)'{-f,--force}"[don't prompt before overwriting]"
+    '(-f --force -i --interactive -n --no-clobber)'{-i,--interactive}'[prompt before overwriting existing file]'
+    '--strip-trailing-slashes[remove any trailing slashes from each source argument]'
+    '(-S --suffix)'{-S+,--suffix=}'[specify the backup suffix]:backup suffix [~]'
+    '(-t --target-directory)'{-t+,--target-directory=}'[move all source arguments into specified directory]:directory:_directories'
+    '(-T --no-target-directory)'{-T,--no-target-directory}'[treat final argument as a normal file]'
+    '(-u --update)'{-u,--update}'[move only when destination file is older or missing]'
+    '(-v --verbose)'{-v,--verbose}'[show file names after they are moved]'
+    '(- *)--help[display usage information]'
+    '(- *)--version[display version information]'
+  )
+  [[ $OSTYPE = linux* ]] && args+=(
+    '(-Z --context)'{-Z,--context}'[set SELinux security context of destination file to default type]'
+  )
+else
+  local pattern arg
+  args=(
+    "(-i -n)-f[don't prompt before overwriting]"
+    '(-f -n)-i[prompt before overwriting existing file]'
+  )
+  for pattern arg in \
+    '(darwin|dragonfly|freebsd)*' "(-f -i)-n[don't overwrite existing file]" \
+    '(darwin|dragonfly|*bsd)*' '-v[show file names after they are moved]' \
+    '(dragonfly|freebsd)*' "-h[if target is a symlink to a directory, don't follow it]"
+  do
+    [[ $OSTYPE = $~pattern ]] && args+=( $arg )
+  done
+fi
+
+_arguments -s -S $args \
+  '*:file:_files'
diff --git a/Completion/Unix/Command/_numfmt b/Completion/Unix/Command/_numfmt
index e69de29bb..999c412a1 100644
--- a/Completion/Unix/Command/_numfmt
+++ b/Completion/Unix/Command/_numfmt
@@ -0,0 +1,24 @@
+#compdef numfmt gnumfmt
+
+local units="((auto\:1K\ =\ 1000,\ 1Ki\ =\ 1024 si\:1K\ =\ 1000 iec\:1K\ =\ 1024 iec-i\:1Ki\ =\ 1024))"
+
+_arguments -S \
+  '(H)--debug[print warnings about invalid input]' \
+  '(H -z --zero-terminated -d --delimiter)'{-d+,--delimiter=}'[use specified field delimiter instead of whitespace]:delimiter' \
+  '(H)--field=[replace numbers in specified input fields]:fields [1]' \
+  '(H)--format=[use printf style floating-point format]:format' \
+  "(H)--from=[auto-scale input numbers to specified units]:unit [none]:$units" \
+  '(H)--from-unit=[specify the input unit size]:unit size [1]' \
+  '(H)--grouping[use locale-defined digit grouping e.g. 1,000,000]' \
+  '(H)--header=-[print (without converting) initial header lines]::header lines [1]' \
+  '(H)--invalid=[specify failure mode for invalid numbers]:mode [abort]:(abort fail warn ignore)' \
+  '(H)--padding=[pad the output to specified width]:width; positive - right-align; negative - left-align' \
+  '(H)--round=[use specified method for rounding when scaling]:method [from-zero]:(up down from-zero towards-zero nearest)' \
+  '(H)--suffix=[add suffix to output numbers and accept optional suffix in input numbers]:suffix' \
+  "(H)--to=[auto-scale output numbers to specified unit]:unit:$units" \
+  '(H)--to-unit=[specify output unit size]:unit size [1]' \
+  '(H -z --zero-terminated -d --delimiter)'{-z,--zero-terminated}'[line delimiter is NUL, not newline]' \
+  '(H)*: :_guard "^-*" number' \
+  + 'H' \
+  '(- *)--help[display usage information]' \
+  '(- *)--version[display version information]'
diff --git a/Completion/Unix/Command/_seq b/Completion/Unix/Command/_seq
index e69de29bb..5b825675f 100644
--- a/Completion/Unix/Command/_seq
+++ b/Completion/Unix/Command/_seq
@@ -0,0 +1,28 @@
+#compdef seq gseq
+
+local variant args
+
+_pick_variant -r variant gnu=GNU $OSTYPE --version
+
+args=( ':: :_guard "^-[^0-9]*" '{first,step,last} )
+case $variant in
+  gnu)
+    args+=(
+      '(--help --version)'{-f+,--format=}'[use printf style floating-point format]:format'
+      '(--help --version -s --separator)'{-s+,--separator=}'[use specified separator for numbers]:separator [\n]'
+      '(--help --version -w --equal-width)'{-w,--equal-width}'[equalize width by padding with leading zeroes]'
+      '(- 1 2 3)--help[display usage information]'
+      '(- 1 2 3)--version[display version information]'
+     )
+  ;;
+  *)
+    args+=(
+      '-f+[use printf style floating-point format]:format'
+      '-s+[use specified separator for numbers]:separator [\n]'
+      '-t+[use specified string to terminate numbers]:string [\n]'
+      '-w[equalize width by padding with leading zeroes]'
+    )
+  ;;
+esac
+
+_arguments -s -A '-[^1-9]*' $args
diff --git a/Completion/Unix/Command/_split b/Completion/Unix/Command/_split
index e69de29bb..25b5aec2d 100644
--- a/Completion/Unix/Command/_split
+++ b/Completion/Unix/Command/_split
@@ -0,0 +1,64 @@
+#compdef split gsplit
+
+local curcontext="$curcontext" variant ret=1
+local -A opt_args
+local -a state line args
+
+_pick_variant -r variant gnu=GNU $OSTYPE --version
+
+args=(
+  '-a+[generate suffixes of specified length]:length [2]' \
+  '(-l -p -n)-b+[put specified size in bytes in each output file]:size (bytes)' \
+  '(-b -p -n)-l+[put specified number of lines/records in each output file]:lines' \
+  '1:file:_files' \
+  '2: :_guard "^-*" "prefix [x]"'
+)
+
+case $variant in
+  gnu)
+    args=( -C
+      '(H -a --suffix-length)'{-a+,--suffix-length=}'[generate suffixes of specified length]:length [2]'
+      '(H)--additional-suffix=[append an additional suffix to file names]:suffix'
+      '(H -b --bytes -C --line-bytes -l --lines -n --number)'{-b+,--bytes=}'[put specified size in bytes in each output file]:size (bytes)'
+      '(H -b --bytes -C --line-bytes -l --lines -n --number)'{-C+,--line-bytes=}'[put whole lines/records up to size limit in each output file]:size (bytes)'
+      '(H --numeric-suffixes -x --hex-suffixes)-d[use numeric suffixes starting at 0]'
+      '(H -d -x --hex-suffixes)--numeric-suffixes=-[use numeric suffixes]::start value [0]'
+      '(H -d --numeric-suffixes --hex-suffixes)-x[use hex suffixes starting at 0]'
+      '(H -d --numeric-suffixes -x)--hex-suffixes=-[use hex suffixes]::start value [0]'
+      '(H -e --elide-empty-files)'{-e,--elide-empty-files}"[don't generate empty output files with '-n']"
+      '(H)--filter=[write to shell command; filename is in $FILE]:command:_cmdstring'
+      '(H -b --bytes -C --line-bytes -l --lines -n --number)'{-l+,--lines=}'[put specified number of lines/records in each output file]:lines'
+      '(H -b --bytes -C --line-bytes -l --lines -n --number)'{-n+,--number=}'[generate specified number of output files]:chunks:->chunks'
+      '(H -t --separator)'{-t+,--separator=}'[use specified record separator instead of newline]:separator'
+      '(H -u --unbuffered)'{-u,--unbuffered}"[immediately copy input to output with '-n r/...']"
+      '(H)--verbose[print a diagnostic just before each output file is opened]'
+      '(H)1:file:_files'
+      '(H)2: :_guard "^-*" "prefix [x]"'
+      + 'H'
+      '(- 1 2)--help[display usage information]'
+      '(- 1 2)--version[display version information]'
+    )
+  ;;
+  (free|net)bsd*)
+    args+=( '(-b -l -p)-n+[generate specified number of output files]:output files' )
+  ;|
+  freebsd*)
+    args+=(
+      '-d[use numeric suffixes]'
+      '(-b -l -n)-p+[split the file whenever a line matches specified pattern]:pattern'
+    )
+  ;;
+esac
+
+_arguments -s -S $args && ret=0
+
+if [[ $state = chunks ]]; then
+  if [[ ! -prefix *[0-9/]* ]]; then
+    _alternative 'modifiers: :_values -s/ "modifier" "l[don'\''t split lines/records]" "r[round robin distribution]"' \
+      'lines: :_guard "[0-9/]#" lines' && ret=0
+  else
+    _message -e lines lines
+  fi
+fi
+
+return ret
diff --git a/Completion/Unix/Command/_stdbuf b/Completion/Unix/Command/_stdbuf
index e69de29bb..3bce3d0a7 100644
--- a/Completion/Unix/Command/_stdbuf
+++ b/Completion/Unix/Command/_stdbuf
@@ -0,0 +1,30 @@
+#compdef stdbuf
+
+local -a short long buf args
+local i opt gnu=0
+
+short=( -e -i -o )
+long=( --error --output --input )
+buf=( err in out )
+
+opt='[set initial buffering for std${buf[i]}]:mode or size:((0\:unbuffered L\:line\ buffered'
+if _pick_variant gnu=GNU freebsd --version; then
+  gnu=1
+  args=(
+    '(- *)--help[display usage information]'
+    '(- *)--version[display version information]'
+  )
+else
+  opt+=' B\:fully\ buffered'
+fi
+opt+='))'
+
+for ((i=1;i<=3;i++)); do
+  args+=( "(${long[i]})${short[i]}+${(e)opt}" )
+  (( gnu )) && args+=(
+    "(${short[i]})${long[i]}=${(e)opt}"
+  )
+done
+(( CURRENT > 2 )) && args+=( '*::command:_normal' )
+
+_arguments -s -S $args
diff --git a/Completion/Unix/Command/_timeout b/Completion/Unix/Command/_timeout
index e69de29bb..0e6d057b3 100644
--- a/Completion/Unix/Command/_timeout
+++ b/Completion/Unix/Command/_timeout
@@ -0,0 +1,19 @@
+#compdef timeout gtimeout
+
+local args
+
+if [[ $service = g* || $OSTYPE != *bsd* ]]; then
+  # GNU coreutils as opposed to Free/NetBSD implementation
+  args=(
+    '(- *)--help[display usage information]'
+    '(- *)--version[display version information]'
+  )
+fi
+
+_arguments -S -A "-" $args \
+  '--preserve-status[always exit with the same status as command even if it times out]' \
+  "--foreground[don't propagate timeout to the command children]" \
+  '(-s --signal)'{-s,--signal}'[specify the signal to send on timeout]:signal:_signals' \
+  '(-k --kill-after)'{-k,--kill-after}'[followup first signal with SIGKILL if command persists after specified time]:time:time' \
+  '1: :_guard "[0-9.]#([smhd]|)" duration' \
+  '*:::command:_normal'
diff --git a/Completion/Unix/Command/_unexpand b/Completion/Unix/Command/_unexpand
index c983c628f..b1d646231 100644
--- a/Completion/Unix/Command/_unexpand
+++ b/Completion/Unix/Command/_unexpand
@@ -1,4 +1,4 @@
-#compdef unexpand
+#compdef unexpand gunexpand
 
 local all tabs ret=1
 local -a args
@@ -7,7 +7,7 @@ all="convert all whitespace, instead of just initial whitespace"
 tabs="use comma separated list of tab positions"
 args=( 
     "(--all)-a[$all]"
-    "(--tabs)-t[$tabs]:tablist"
+    "(--tabs)-t+[$tabs]:tablist"
     "*:file:_files"
 )
 
@@ -21,6 +21,6 @@ if _pick_variant gnu="Free Soft" unix --version; then
     )
 fi
 
-_arguments "$args[@]" && ret=0
+_arguments -s -S "$args[@]" && ret=0
 
 return ret


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

* Re: PATCH: completion for a few more coreutils things
  2017-10-06 22:16 PATCH: completion for a few more coreutils things Oliver Kiddle
@ 2017-10-10  6:18 ` Jun T
  2017-10-10  8:57   ` Peter Stephenson
  2017-10-10  9:16   ` Oliver Kiddle
  0 siblings, 2 replies; 7+ messages in thread
From: Jun T @ 2017-10-10  6:18 UTC (permalink / raw)
  To: zsh-workers


> 2017/10/07 7:16, Oliver Kiddle <okiddle@yahoo.co.uk> wrote:
> 
>  expand, mv, numfmt, seq, split, stdbuf, timeout

The file Completion/Unix/Command/_expand need be renamed because _expand
already exists in Completion/Base/Completer/_expand.

Jun


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

* Re: PATCH: completion for a few more coreutils things
  2017-10-10  6:18 ` Jun T
@ 2017-10-10  8:57   ` Peter Stephenson
  2017-10-10  9:16   ` Oliver Kiddle
  1 sibling, 0 replies; 7+ messages in thread
From: Peter Stephenson @ 2017-10-10  8:57 UTC (permalink / raw)
  To: zsh-workers

On Tue, 10 Oct 2017 15:18:36 +0900
Jun T <takimoto-j@kba.biglobe.ne.jp> wrote:
> > 2017/10/07 7:16, Oliver Kiddle <okiddle@yahoo.co.uk> wrote:
> > 
> >  expand, mv, numfmt, seq, split, stdbuf, timeout
> 
> The file Completion/Unix/Command/_expand need be renamed because _expand
> already exists in Completion/Base/Completer/_expand.

Ah, yes, this is playing merry hell and causing completion not to work
at all any more...

I'll rename it immediately to _expand_cmd or I'm not going to be able to
do any work --- this doesn't need to be the final name.

pws


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

* Re: PATCH: completion for a few more coreutils things
  2017-10-10  6:18 ` Jun T
  2017-10-10  8:57   ` Peter Stephenson
@ 2017-10-10  9:16   ` Oliver Kiddle
  2017-10-11  1:23     ` Daniel Shahaf
  1 sibling, 1 reply; 7+ messages in thread
From: Oliver Kiddle @ 2017-10-10  9:16 UTC (permalink / raw)
  To: zsh-workers

Jun T wrote:
> The file Completion/Unix/Command/_expand need be renamed because _expand
> already exists in Completion/Base/Completer/_expand.

Oh yes. That'll break things fairly badly, sorry.

expand and unexpand completion have a few things in common so
perhaps the best is just to roll expand completion into _unexpand.

Oliver

diff --git a/Completion/Unix/Command/_unexpand b/Completion/Unix/Command/_unexpand
index d9793ea70..13f6ce835 100644
--- a/Completion/Unix/Command/_unexpand
+++ b/Completion/Unix/Command/_unexpand
@@ -1,26 +1,33 @@
-#compdef unexpand gunexpand
+#compdef unexpand gunexpand expand gexpand
 
-local all tabs ret=1
+local all tabs
 local -a args
 
 all="convert all whitespace, instead of just initial whitespace"
-tabs="use comma separated list of tab positions"
-args=( 
-  "(--all)-a[$all]"
-  "(--tabs)-t+[$tabs]:tablist"
-  '*:file:_files'
-)
+tabs="[use comma separated list of tab positions]:list of tab positions"
 
 if _pick_variant gnu="Free Soft" unix --version; then
+  if [[ $service = *un* ]]; then
+    args=(
+      "(-a --help --version)--all[$all]"
+      '(--help --version)--first-only[convert only leading sequences of whitespace]'
+    )
+  else
+    args=(
+      '(-i --initial --help --version)'{-i,--initial}"[don't convert tabs after non blanks]"
+    )
+  fi
+
   args+=(
-    "(-a)--all[$all]"
-    '--first-only[convert only leading sequences of whitespace]'
-    "(-t)--tabs=[$tabs]:tablist"
+    "(-t --help --version)--tabs=${tabs}"
     '(* -)--help[display usage information]'
-    '(* -)--version[output version information]'
+    '(* -)--version[display version information]'
   )
+elif [[ $OSTYPE = (*bsd*|dragonfly*|darwin*) ]]; then
+  args=( -A "-*" )
 fi
+[[ $service = *un* ]] && args+=(  "(--all --help --version)-a[$all]" )
 
-_arguments -s -S "$args[@]" && ret=0
-
-return ret
+_arguments -s -S "$args[@]" \
+  "(--tabs --help)-t+${tabs}" \
+  '*:file:_files'


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

* Re: PATCH: completion for a few more coreutils things
  2017-10-10  9:16   ` Oliver Kiddle
@ 2017-10-11  1:23     ` Daniel Shahaf
  2017-10-11 16:45       ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Shahaf @ 2017-10-11  1:23 UTC (permalink / raw)
  To: zsh-workers

Oliver Kiddle wrote on Tue, 10 Oct 2017 11:16 +0200:
> Jun T wrote:
> > The file Completion/Unix/Command/_expand need be renamed because _expand
> > already exists in Completion/Base/Completer/_expand.
> 
> Oh yes. That'll break things fairly badly, sorry.

Can we make this situation a build error in the future?


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

* Re: PATCH: completion for a few more coreutils things
  2017-10-11  1:23     ` Daniel Shahaf
@ 2017-10-11 16:45       ` Bart Schaefer
  2017-10-11 17:56         ` Daniel Shahaf
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2017-10-11 16:45 UTC (permalink / raw)
  To: zsh-workers

On Oct 11,  1:23am, Daniel Shahaf wrote:
} Subject: Re: PATCH: completion for a few more coreutils things
}
} Oliver Kiddle wrote on Tue, 10 Oct 2017 11:16 +0200:
} > Jun T wrote:
} > > The file Completion/Unix/Command/_expand need be renamed because _expand
} > > already exists in Completion/Base/Completer/_expand.
} > 
} > Oh yes. That'll break things fairly badly, sorry.
} 
} Can we make this situation a build error in the future?

Having two files with the same name is not necessarily an error; the
intent has been that we might have one file for openSUSE and another
for Solaris, etc., and the local packager was responsible for putting
the correct one in the installation (or correct directory in fpath).

(On the other hand we've never given much configure/install help for
how to select the right one.)

Two files with the same name and incompatible #compdef lines is another
matter, but I don't have any good ideas for determining "incompatible."


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

* Re: PATCH: completion for a few more coreutils things
  2017-10-11 16:45       ` Bart Schaefer
@ 2017-10-11 17:56         ` Daniel Shahaf
  0 siblings, 0 replies; 7+ messages in thread
From: Daniel Shahaf @ 2017-10-11 17:56 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote on Wed, 11 Oct 2017 09:45 -0700:
> On Oct 11,  1:23am, Daniel Shahaf wrote:
> } Subject: Re: PATCH: completion for a few more coreutils things
> }
> } Oliver Kiddle wrote on Tue, 10 Oct 2017 11:16 +0200:
> } > Jun T wrote:
> } > > The file Completion/Unix/Command/_expand need be renamed because _expand
> } > > already exists in Completion/Base/Completer/_expand.
> } > 
> } > Oh yes. That'll break things fairly badly, sorry.
> } 
> } Can we make this situation a build error in the future?
> 
> Having two files with the same name is not necessarily an error; the
> intent has been that we might have one file for openSUSE and another
> for Solaris, etc., and the local packager was responsible for putting
> the correct one in the installation (or correct directory in fpath).
> 
> (On the other hand we've never given much configure/install help for
> how to select the right one.)
> 
> Two files with the same name and incompatible #compdef lines is another
> matter, but I don't have any good ideas for determining "incompatible."

"Not in a whitelist of known-good collisions"

I.e., default to erroring out on all collisions except those specifically whitelisted.

Just an idea...

Daniel


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

end of thread, other threads:[~2017-10-11 17:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-06 22:16 PATCH: completion for a few more coreutils things Oliver Kiddle
2017-10-10  6:18 ` Jun T
2017-10-10  8:57   ` Peter Stephenson
2017-10-10  9:16   ` Oliver Kiddle
2017-10-11  1:23     ` Daniel Shahaf
2017-10-11 16:45       ` Bart Schaefer
2017-10-11 17:56         ` Daniel Shahaf

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).